Skip to content

Added signout controller #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from

Conversation

Shubham-1105
Copy link
Contributor

resolves #84

// @access Private

router.post("/logout", auth, async (req, res) => {
res.clearCookie("token");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have to invalidate the token
Meaning -> Find this token (in user's token array ) and remove it from that array. Save the changes made.

msg: "User Signout Successfully",
});
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, please include screenshots in your PRs,
There is almost a week left so hurry up.
You won't be able to get points after 20th Nov.

// @desc Logout a user
// @access Private

router.post("/logout", auth, async (req, res) => {
Copy link
Contributor

@BhavyaaArora-08 BhavyaaArora-08 Nov 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you can make the below listed changes by today, I will merge the PR and you will be awarded points else not.

logged in user is available at req.user and the token he has been using to access the private routes is available at req.token. Why? All of this has been handled in the auth middleware.
Also all the tokens he has been given so far is present in tokens array, (req.user.tokens)

  1. To log him out, simply delete req.token from req.user.tokens. And update the user in the User model too.

Also, You should know how to test your API endpoints.
https://www.youtube.com/watch?v=t5n07Ybz7yI
Here's a video that might be helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add user logout route.
2 participants