Fakultas Ilmu Komputer UI

Commit dde06526 authored by Muhammad Rafif Elfazri's avatar Muhammad Rafif Elfazri
Browse files

Remove guardian plug on api/auth

parent 594751f7
...@@ -59,12 +59,20 @@ defmodule DiskuyWeb.UserController do ...@@ -59,12 +59,20 @@ defmodule DiskuyWeb.UserController do
# end # end
def callback(conn, _params) do def callback(conn, _params) do
token = Guardian.Plug.current_token(conn) token_header = get_req_header(conn, "authorization")
case token_header do
[] ->
{:error, :unauthorized}
["Bearer", token|_] = String.split(token_bearer, " ")
with {:ok, user, new_token}= GoogleAuth.create_local_token(token) do with {:ok, user, new_token}= GoogleAuth.create_local_token(token) do
conn conn
|> put_status(:created) |> put_status(:created)
|> render("user_token.json", %{user: user, token: new_token}) |> render("user_token.json", %{user: user, token: new_token})
end end
_ ->
{:error, :bad_request}
end end
end end
...@@ -58,7 +58,7 @@ defmodule DiskuyWeb.Router do ...@@ -58,7 +58,7 @@ defmodule DiskuyWeb.Router do
end end
scope "/api/auth", DiskuyWeb do scope "/api/auth", DiskuyWeb do
pipe_through [:api, :auth_token] pipe_through :api
get "/google/callback", UserController, :callback get "/google/callback", UserController, :callback
options "/google/callback", UserController, :options options "/google/callback", UserController, :options
end end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment