Allowing a user to navigate to their profile page

Right now it's actually difficult to navigate to the user's profile page to actually be able to generate our API key, so we'll take a quick sidebar to implement that. We'll start off by returning to the main application layout, lib/vocial_web/templates/layout/app.html.eex and modify the render call for _nav.html to pass in the conn:

<%= render "_nav.html", conn: @conn %>

Then we'll hop over to the _nav.html.eex template, where we'll change the login link to instead be conditional based on information that should be in the session:

<%= if user = Plug.Conn.get_session(@conn, :user) do %>
<li><%= link "Welcome #{user.username}", to: user_path(@conn, :show, user.id) %></li>
<% else %>
<li><a href="/login">Login</a></li>
<% end %>

This should make it a lot simpler for the user to find their way back to the user profile! After the user logs in, at the top (in the navigation bar), they should see a Welcome ____ link. Clicking that will bring us to the user profile page!

Now we can actually direct a user easily to their profile page, which will be necessary for the next steps! As I mentioned, this is a pretty easy thing for us to implement and will be well worth the small amount of effort for the next bit of work and testing that we'll need to do!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset