Skip to content

Commit

Permalink
feat(router): implemented auth for protected routes
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabrielparizet committed Jul 3, 2024
1 parent 6ae76e8 commit 4476a91
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/book_my_gigs_web/accounts/accounts_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ defmodule BookMyGigsWeb.AccountsController do
]
)

def sign_in(conn, %{"account" => %{"email" => email, "hash_password" => hash_password}}) do
case BookMyGigs.Guardian.authenticate(email, hash_password) do
def sign_in(conn, %{"account" => %{"email" => email, "password" => password}}) do
case BookMyGigs.Guardian.authenticate(email, password) do
{:ok, account, token} ->
response =
Jason.encode!(%{account: Accounts.to_context_struct(account), token: token})
Expand Down
10 changes: 4 additions & 6 deletions lib/book_my_gigs_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,17 @@ defmodule BookMyGigsWeb.Router do
end

scope "/", BookMyGigsWeb do
pipe_through :browser
pipe_through [:api]
post "/accounts", AccountsController, :create

get "/", PageController, :home
post "/accounts/sign_in", AccountsController, :sign_in
end

scope "/api", BookMyGigsWeb do
pipe_through :api
pipe_through [:api, :auth]
get "/accounts", AccountsController, :get
post "/accounts", AccountsController, :create
put "/accounts/:id", AccountsController, :update
delete "/accounts/:id", AccountsController, :delete

post "/accounts/sign_in", AccountsController, :sign_in
end

# Other scopes may use custom stacks.
Expand Down

0 comments on commit 4476a91

Please sign in to comment.