wolfiton
Hello,
I was searching the documentation to find a way to set multiple session cookies from my pheonix api to my frontend, in my case a nextjs app.
I need to set a cookie with my userid and another one with my user role.
How can i set my cookies?
Also I am not looking for JWT or local storage.
Thank you in advance
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security










Showing Posts 1 to 9- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
NobbZ
I think you are searching for
Plug.Conn.put_session/3, or–if you need more detailed control over the cookie itself–Plug.Conn.put_resp_cookie/4.wolfiton
Thanks that show how i can plug it in, but i am wondering how I can set them in my endpoint.
The documentation only gives this example
Do I redo this plug again with my new key like this?
Then i add them like this?
put_resp_cookie(conn, “_hello_key”)
put_resp_cookie(conn, “_second_cookie_key”)
Or there is another way?
NobbZ
Well,
Plug.Sessionactually just stores a single value which again is a map serialized, signed and encrypted.If you really want to have distinct cookie values, you have no choice but to use
Plug.Conn.put_resp_cookie/4.wolfiton
Can you show me an example on how to use this
Plug.Conn.put_resp_cookie/4?Because i can’t imagine how it looks and the documentation doesn’t provide an example in this case?
Thanks
NobbZ
You may need to tweak the options.
thojanssens1
I think you don’t need that additional
Plug.Sessionplug to add cookies withput_resp_cookieas @wolfiton showed in his first reply?Also I was wondering, why do we have
put_resp_cookiebut noget_resp_cookie, what is the idiomatic way to retrieve one of the cookies then?wolfiton
Hi @thojanssens1
We use the plug so that we can attach our cookie with the conn that will be send in to the view.
This article should explain better how plug works Plug · Elixir School
Plug — Phoenix v1.8.8
alvises
so you manually sign and encrypt the value you pass to
put_resp_cookie/4right?wolfiton
You can use tokens for this and create them with Phoenix token.
Then you use them in your cookie
Here is an example form the documentation
Here is the documentation Phoenix.Token — Phoenix v1.8.8
Also a good read https://phoenixframework.org/blog/sessions