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.

Revisions

  1. Nicolas Blanco created this gist Feb 20, 2018.
    19 changes: 19 additions & 0 deletions auth_controller.ex
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    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
    10 changes: 10 additions & 0 deletions guardian_pipeline.ex
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    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