Fakultas Ilmu Komputer UI

Commit 8469c1ae authored by Muhammad Rafif Elfazri's avatar Muhammad Rafif Elfazri
Browse files

Add new module for google auth

parent 919b3f1a
defmodule DiskuyWeb.Auth.GoogleAuth do
alias DiskuyWeb.Auth.Guardian
alias Diskuy.Account
def get_access_token(code, conn) do
case ElixirAuthGoogle.get_token(code, conn) do
{:ok, profile} ->
{:ok, profile}
_ ->
{:error, :bad_request}
end
end
def create_local_token(token) do
{:ok, profile} = ElixirAuthGoogle.get_user_profile(token.access_token)
{email, username, picture} = {profile[:email], profile[:name], profile[:picture]}
case Account.get_by_email(email) do
{:ok, user} ->
Guardian.create_token(user)
{:error, :not_found} ->
{:ok, user} = Account.create_user(%{username: username, email: email, picture: picture})
Guardian.create_token(user)
end
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