Implement Log out Functionality and Only Allow Logged in Users to See Posts

InstructorIan Jones

Share this video with your friends

Send Tweet

Currently the only way to know if you are logged in is if you check the cookie that is set in the browser. This isn’t super user friendly. You want to add a visual cue as well as a log out button to the nav. 

To accomplish this, you can check if a user exists with the isAuthenticated function that was created in the auth service. If there is a user you will display their email, loaded up from the isAuthenticated check, as well as a log out button.

The log out button will post to a resource route. This route will log out the user and redirect them to the log in page.

Finally, you will lock up the index page so only logged in users can see and add posts.