How to log a user out with Replit Auth in Node.js

Question:
I am currently writing a auth system for a fourm I am making, but I cannot figure out how to log the user out. Is there a way to log the user out while using Replit Auth?


Repl link:
https://replit.com/@Raddelgo14/CodeFourms-1?v=1

//This is what I have for the coder right now, what do I need to add or remove
// To make this work
app.get('/logout', (req, res) => {
  user = getUserInfo(req);
  user.logout();
  res.send("Logged Out");
})
1 Like

You could clear the cookie of the page (if there is not a built-in function.) If your page doesn’t store any other cookies besides ReplAuth, then I think you could just redirect to a page that runs

document.cookie=""

and it will log them out of your site.

2 Likes

I have sloved it, I had to put a bunch more stuff in it for it to work

1 Like

What did you do? (in case other people find this post looking for an answer)

And then mark that post as a solution.

1 Like

I used

app.post('/api/logout', (req, res) =>{ res.clearCookie('REPL_AUTH',{path:'/',domain:'.codefourms-1.raddelgo14.repl.co'}); console.log("User is logged out."); return res.status(200).redirect('/'); });

2 Likes

Well yeah, document is only in frontend JS, not Node

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.