How to use current_user in Elixir's Phoenix Framework

authentication
phoenix
learning-elixir
#1

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.

https://blog.remote.com/current-user-in-elixir-phoenix/

1 Like

#2

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.

1 Like

#3

Thanks for the comment :slight_smile: 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.

1 Like

#4

Isn’t coherence dead?

0 Likes

#5

It’s not being as actively maintained, some people are moving to Pow.

0 Likes