Skip to content

Commit

Permalink
updated tutorial (#637)
Browse files Browse the repository at this point in the history
Co-authored-by: Benson Pan <[email protected]>
  • Loading branch information
doomspork and panbenson authored Jan 9, 2020
1 parent b947b44 commit b8a4945
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions guides/tutorial/start-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ defmodule AuthMe.UserManager.Guardian do
end

def resource_from_claims(%{"sub" => id}) do
UserManager.get_user!(id)
user = UserManager.get_user!(id)
{:ok, user}
rescue
e in Ecto.NoResultsError => {:error, :resource_not_found}
end
end
```
Expand Down Expand Up @@ -193,7 +196,7 @@ At this point, the autogenerated tests when we first created the UserManager and
Fixing the broken tests is simple: we want to compare the encrypted passwords instead of plain text ones.

```elixir
## test/auth_me/auth_test.exs
## test/auth_me/user_manager_test.exs

...

Expand Down Expand Up @@ -294,17 +297,17 @@ defmodule AuthMeWeb.SessionController do

def logout(conn, _) do
conn
|> Guardian.Plug.sign_out() #This module's full name is Auth.UserManager.Guardian.Plug,
|> Guardian.Plug.sign_out() #This module's full name is Auth.UserManager.Guardian.Plug,
|> redirect(to: "/login") #and the arguments specfied in the Guardian.Plug.sign_out()
end #docs are not applicable here
end #docs are not applicable here

defp login_reply({:ok, user}, conn) do
conn
|> put_flash(:info, "Welcome back!")
|> Guardian.Plug.sign_in(user) #This module's full name is Auth.UserManager.Guardian.Plug,
|> redirect(to: "/protected") #and the arguments specified in the Guardian.Plug.sign_in()
end #docs are not applicable here.
|> redirect(to: "/protected") #and the arguments specified in the Guardian.Plug.sign_in()
end #docs are not applicable here.

defp login_reply({:error, reason}, conn) do
conn
|> put_flash(:error, to_string(reason))
Expand Down Expand Up @@ -441,5 +444,8 @@ Now exit iex and start up your server:
$ mix phx.server
```

Enter `localhost:4000/protected` in your browser's address bar, and you should see "unathenticated". Now, enter `localhost:4000/login` in your browser's address bar, and login with your `me` username and `secret` password. You should automatically be redirected to the protected page, which you can now see! To logout, enter `localhost:4000/logout` in your browser's address bar, and you will be redirected to the login page. Instead of logging in, enter `localhost:4000/protected` in your browser's address bar, and you will see "unathenticated" again!

Enter `localhost:4000/protected` in your browser's address bar, and you should see "unauthenticated".
Now, enter `localhost:4000/login` in your browser's address bar, and login with your `me` username and `secret` password.
You should automatically be redirected to the protected page, which you can now see!
To logout, enter `localhost:4000/logout` in your browser's address bar, and you will be redirected to the login page.
Instead of logging in, enter `localhost:4000/protected` in your browser's address bar, and you will see "unauthenticated" again!

0 comments on commit b8a4945

Please sign in to comment.