marcelo
How to use current_user in Elixir's Phoenix Framework
I wrote a small article on how to use current_user with coherence on Phoenix. There are already a couple of blogposts about it but I think it’s still worth sharing.
Most Liked
LostKobrakai
You already have current_user in your conn.assigns, so you can just use @current_user in your views. Everything you manually pass to render/3 in your controller will be merged with conn.assigns before being passed to the view layer. There’s no need for assigning the user again in the controller action.
Also I see you’re using the “action overwrite” in controllers. I usually pass [conn, conn.params, conn.assigns] to controller actions, so I can pattern match data out of assigns if the actions need some data for doing their job.
marcelo
Thanks for the comment
This use case for current_user is to use it explicitly in controller actions not in views (if that were the case then what you described is ofc the way to go). In this blogpost we passed the current_user var down from the controller to the view just as an example.
DiodonHystrix
Isn’t coherence dead?
Popular in Guides/Tuts
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








