diff --git a/guides/tutorial/start-tutorial.md b/guides/tutorial/start-tutorial.md index c122bff30..c3d480c2c 100644 --- a/guides/tutorial/start-tutorial.md +++ b/guides/tutorial/start-tutorial.md @@ -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 ``` @@ -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 ... @@ -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)) @@ -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!