Skip to content

Instantly share code, notes, and snippets.

@nicolasblanco
Created February 20, 2018 16:16
Show Gist options
  • Save nicolasblanco/4de1b989a928954c4077de098617b416 to your computer and use it in GitHub Desktop.
Save nicolasblanco/4de1b989a928954c4077de098617b416 to your computer and use it in GitHub Desktop.
defmodule DokkitoWeb.AuthController do
use DokkitoWeb, :controller
# ...
def callback(%{assigns: %{ueberauth_auth: auth}} = conn, _params) do
case Auth.find_or_create(auth) do
{:ok, user} ->
conn
|> put_flash(:info, "Successfully authenticated.")
|> Guardian.Plug.sign_in(user, key: :user)
|> redirect(to: dashboard_home_path(conn, :index))
{:error, reason} ->
conn
|> put_flash(:error, reason)
|> redirect(to: "/")
end
end
end
defmodule DokkitoWeb.Plug.GuardianPipeline do
use Guardian.Plug.Pipeline, otp_app: :dokkito,
module: DokkitoWeb.Guardian,
error_handler: DokkitoWeb.Plug.AuthErrorHandler,
key: :user
plug Guardian.Plug.VerifySession
plug Guardian.Plug.EnsureAuthenticated
plug Guardian.Plug.LoadResource
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment