coherence icon indicating copy to clipboard operation
coherence copied to clipboard

Get user when redirecting

Open cdesch opened this issue 8 years ago • 1 comments

How do you get user during the session_create controller action? For example, if you are redirecting the page that the user is redirected to after login based on an attribute that belongs to user (e.g. users role), how do you get the user in that context?

Getting the user via Coherence.current_user(conn) does get it.

Non-working attempt:

def session_create(conn, _) do
   user = Coherence.current_user(conn)
   IO.inspect user
   if user.role == 1 do
     redirect(conn, to: home_path(conn, :index))
   end
 
   if user.role == 2 do
     redirect(conn, to: admin_path(conn, :dashboard))
   end
 end

cdesch avatar Aug 03 '17 23:08 cdesch

Would this be better done using plug? In retrospect, this may be the wrong approach to decide which page the different types of users should be redirected to on login.

Edit:

Or maybe set Config.logged_in_url to a helper function that set's based on the user.... that doesn't seem like a good practice.

cdesch avatar Aug 04 '17 17:08 cdesch