Created
February 20, 2018 16:16
-
-
Save nicolasblanco/4de1b989a928954c4077de098617b416 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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