Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Clivern committed Feb 5, 2024
1 parent a66f052 commit aec2019
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
33 changes: 16 additions & 17 deletions lib/brangus/middleware/auth.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,29 @@ defmodule Brangus.Service.AuthMiddleware do
conn.req_cookies["_token"]
)

case result do
conn = case result do
false ->
conn = assign(conn, :is_logged, false)
conn = assign(conn, :user_role, :anonymous)
conn = assign(conn, :user_id, "")
conn = assign(conn, :sess_token, "")
conn
assign(conn, :is_logged, false)
|> assign(conn, :user_role, :anonymous)
|> assign(conn, :user_id, "")
|> assign(conn, :sess_token, "")

{true, session} ->
case UserModule.get_user_by_id(session.user_id) do
conn = case UserModule.get_user_by_id(session.user_id) do
{:ok, user} ->
conn = assign(conn, :is_logged, true)
conn = assign(conn, :user_role, String.to_atom(user.role))
conn = assign(conn, :user_id, session.user_id)
conn = assign(conn, :sess_token, session.value)
conn
assign(conn, :is_logged, true)
|> assign(conn, :user_role, String.to_atom(user.role))
|> assign(conn, :user_id, session.user_id)
|> assign(conn, :sess_token, session.value)

{:not_found, _} ->
conn = assign(conn, :is_logged, false)
conn = assign(conn, :user_role, :anonymous)
conn = assign(conn, :user_id, "")
conn = assign(conn, :sess_token, "")
conn
assign(conn, :is_logged, false)
|> assign(conn, :user_role, :anonymous)
|> assign(conn, :user_id, "")
|> assign(conn, :sess_token, "")
end

conn
end

conn
Expand Down
12 changes: 6 additions & 6 deletions lib/brangus_web/controllers/page_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ defmodule BrangusWeb.PageController do

conn = case result do
false ->
assign(conn, :is_logged, false)
|> assign(:user_id, "")
|> assign(:user_token, "")
assign(conn, :is_logged, false)
|> assign(:user_id, "")
|> assign(:user_token, "")

{true, session} ->
assign(conn, :is_logged, true)
|> assign(:user_id, session.user_id)
|> assign(:user_token, session.value)
assign(conn, :is_logged, true)
|> assign(:user_id, session.user_id)
|> assign(:user_token, session.value)
end

conn
Expand Down

0 comments on commit aec2019

Please sign in to comment.