Comments (6)
I pulled latest NITRO/N2O and tested your added interfaces, nitro:cookie/2 and cookie/3, seems to work fine! (thanks for adding) Thx also for fixing #api callback issue!
For completeness, would be good if you could add this function to get a certain cookie also since they are already in the context.
cookies() -> cowboy_req:parse_cookies((get(context))#cx.req).
cookie(Key) -> case lists:keyfind(Key, 1, cowboy_req:parse_cookies((get(context))#cx.req)) of false -> undefined; {_, Value} -> Value end.
Worth mentioning that the set cookie is not visible until next page reload.
Regarding moving n2o_nitro from N2O to NITRO, seems fine to me.
from nitro.
We removed cookies from N2O since 5.11, but added into NITRO 4.7.3 the following API:
iex(1)> :nitro.cookie 'hello', 'world'
[]
iex(2)> :erlang.get :actions
[
{:wire, :action, [], [], :action_wire,
'document.cookie=\'hello=world; path=/; expires=Sat, 26-Jul-2087 00:56:15 GMT\';',
[]}
]
you can use in inside your pages. The full example here: o7/plm@e262877
defmodule PLM.Login do
use N2O, with: [:n2o, :nitro]
use FORM
require Logger
def event(:init) do
NITRO.clear(:stand)
NITRO.cookie 'hello', 'world'
NITRO.wire(api(name: 'getCookies', delegate: PLM.Login))
mod = PLM.Forms.Pass
NITRO.insert_bottom(:stand, FORM.new(mod.new(mod, mod.id()), mod.id()))
end
def event({:SMS, _}), do: NITRO.wire("document.getCookies('sample string');")
def event(any), do: IO.inspect any
def api_event(_,_,_), do: IO.inspect "API EVENT~n"
end
from nitro.
Maybe it's time to move n2o_nitro
to NITRO as well. Let me know what do you think!
from nitro.
Worth mentioning that the set cookie is not visible until next page reload.
It was to be in sync with cookies ETS table in 5.11 I just removed this. We had server-side controlled cookies, that's why we had infinite expire time. If you want server controlled cookies we need an additional table not mix them with session variables n2o:session (sessions), nitro:cookie (cookies).
from nitro.
In my use cases, it is enough that they are visible after page reload, i.e. browser controlled cookies.
Would be nice if you could add to nitro.erl :
cookies() -> cowboy_req:parse_cookies((get(context))#cx.req).
cookie(Key) -> case lists:keyfind(Key, 1, cowboy_req:parse_cookies((get(context))#cx.req)) of false -> undefined; {_, Value} -> Value end.
You could close this ticket as solved anyway.
from nitro.
It's added in 4.7.4 eb3fe4b
from nitro.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nitro.