Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

365
Views
Deleting cookie in client from server failing (Firefox)

Im trying to delete the cookies in the client that my server created every time the user logout, they have httpOnly:true attr so only the server response can delete it automatically. I already tried my app in Chrome, Firefox, Edge. Its working will with the other 2 browser, the code deletes it automatically from the cookies after logout, but in firefox its not, the cookies is still there. Here's my code

server/backend

const logoutUser = asyncHandler(async(req, res) => {

    const cookies = req.cookies;
    
    res.cookie('jwt', 'none', {
        expires: new Date(Date.now() + 1 * 1000),
        httpOnly: true,
        secure: true, 
        sameSite: 'None',
    })
    
    res.clearCookie('jwt', { httpOnly: true, sameSite: 'None', secure: true });
    res.sendStatus(204);
    
    if (!cookies?.jwt) return res.sendStatus(401); //No content
    const refreshToken = cookies.jwt;

    // Is refreshToken in db?
    const foundUser = await User.findOne({ refreshToken }).exec();
    if (!foundUser) {
        res.clearCookie('jwt', { httpOnly: true, sameSite: 'None', secure: true });
        return res.sendStatus(204);
    }

    // Delete refreshToken in db
    foundUser.refreshToken = foundUser.refreshToken.filter(rt => rt !== refreshToken);
    const result = await foundUser.save();
    console.log(result);

    
})

client/frontend

 const logout = async () => {

        
        localStorage.removeItem('userpersist')
        document.cookie = "userpersist=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
        
        try {
            await apiClient.get('/logout', {
                withCredentials: true
            });
        } catch (err) {
            console.error(err);
        }
    
    }

And also another question: Why I'm instantly redirected to home page '/' even though I haven't set up my navigation yet after user press logout?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!