ueberauth / guardian

Elixir Authentication
MIT License
3.43k stars 382 forks source link

Check if a user is authenticated #191

Closed GildedHonour closed 8 years ago

GildedHonour commented 8 years ago

After a user signed in:

def create(conn, params = %{}) do
    conn
    |> put_flash(:info, "Logged in.")
    |> Guardian.Plug.sign_in(verified_user) # verify your logged in resource
    |> redirect(to: user_path(conn, :index))
  end

how do I check on if they are authenticated in other places? Say, a page "users/secret_page" is avaialble only for authenticated users. When a user comes to that page, how do I check if they're authenticated?

migore commented 8 years ago

O just found this, it helped me. Hope it helps. https://hexdocs.pm/guardian/Guardian.Plug.html#authenticated?/1

doomspork commented 8 years ago

Hi @GildedHonour, have you looked at Guardian.Plug.EnsureAuthenticated?

https://github.com/ueberauth/guardian#guardianplugensureauthenticated

GildedHonour commented 8 years ago

Thanks. It doesn't support password recovering, email confirmations, locking users and so on?

doomspork commented 8 years ago

@GildedHonour that functionality isn't provided by Guardian. If you're familiar with the Ruby ecosystem Guardian is akin to Warden upon which Devise (and others) are built.

GildedHonour commented 8 years ago

@doomspork what do you recommend to use as alternive of devise gem from Rails?

doomspork commented 8 years ago

@GildedHonour as far I as know no one has built something like Devise for Elixir. For my use-cases I roll my own functionality.

GildedHonour commented 8 years ago

Thanks.