Git Product home page Git Product logo

Comments (17)

vvo avatar vvo commented on May 18, 2024 6

@dpyzo0o I just updated the next-iron-session repository and now recommend another solution: just make sure to call any route that uses destroy via a POST request. Most proxies and browsers (100%?) will never cache POST requests unless badly or weirdly configured.

The two solutions have the same effect, but using POST for logout is more common practice I think.

Thanks!

from iron-session.

elie222 avatar elie222 commented on May 18, 2024 1

Changing my endpoint to POST seems to have fixed it now

from iron-session.

behzad-ahmadi avatar behzad-ahmadi commented on May 18, 2024 1

The problem is not solved yet?!

UPDATE:
the request should be POST to solve the problem.

from iron-session.

vvo avatar vvo commented on May 18, 2024

Thanks for the detailed bug report and first analysis.
The failing version is 10.0.2. Now we need to:

  • understand if they fixed a bug, which in turn made our code buggy (and we should update our code)
  • or if they introduced a bug (and we need to find it, and they/we need to fix it)
  • find/identity the right change here: https://github.com/vercel/next.js/releases/tag/v10.0.2
  • or maybe the change in on the Vercel platform itself

I am doing some tests right now, let me know how it goes on your side

from iron-session.

vvo avatar vvo commented on May 18, 2024

More info on the issue: this is because of the caching mechanism. Now why has it changed on the latest Next.js versions: I don't know and I think you should write to the Vercel support to know more.

A possible workaround for now would be to manually set caching headers (informing not to cache) on all your API routes that are setting up cookies like login and logout.

from iron-session.

dpyzo0o avatar dpyzo0o commented on May 18, 2024

More info on the issue: this is because of the caching mechanism. Now why has it changed on the latest Next.js versions: I don't know and I think you should write to the Vercel support to know more.

A possible workaround for now would be to manually set caching headers (informing not to cache) on all your API routes that are setting up cookies like login and logout.

I have tried to manually set the headers res.setHeader('cache-control', 'public, max-age=0, must-revalidate') and it does not seem to work. I'm not an expert on the http caching so I don't know if I'm doing the right way...

from iron-session.

dpyzo0o avatar dpyzo0o commented on May 18, 2024

This might be the related change https://github.com/vercel/next.js/pull/18986/files

from iron-session.

vvo avatar vvo commented on May 18, 2024

Hey there @dpyzo0o there's definitely something strange that changed between Vercel/Next.js, in the meantime you can set res.setHeader("cache-control", "no-store, max-age=0"); on your logout route and that should do it, even on Vercel.

Let me know!

from iron-session.

dpyzo0o avatar dpyzo0o commented on May 18, 2024

@vvo Thanks, it works.

from iron-session.

vvo avatar vvo commented on May 18, 2024

🎉 This issue has been resolved in version 4.1.11 🎉

The release is available on:

Your semantic-release bot 📦🚀

from iron-session.

Deivaras avatar Deivaras commented on May 18, 2024

🎉 This issue has been resolved in version 4.1.11 🎉

The release is available on:

Your semantic-release bot 📦🚀

Everything works on:
Google Chrome Version 88.0.4324.150 (Official Build) (64-bit) with
"next": "^10.0.6",
"next-iron-session": "^4.1.11"
on development and production on Vercel. Also sometimes it takes two clicks to login.

Does not work on Vercel with:
Firefox 85.0.2 (64-bit);
Firefox developer edition 86.0b8 (64-bit);

from iron-session.

vvo avatar vvo commented on May 18, 2024

hey @Deivaras I believe this notification was long due sorry about that.

Are you using POST requests for logout routes now? I do have that double clicks to logout issue yup, did not investigate (not login though, login is always OK).

from iron-session.

Deivaras avatar Deivaras commented on May 18, 2024

hey @Deivaras I believe this notification was long due sorry about that.

Are you using POST requests for logout routes now? I do have that double clicks to logout issue yup, did not investigate (not login though, login is always OK).

Yes, I'm doing POST request on logout fetch and also on Chrome sometimes when trying to login (after first click) I see the cookie and then you have to click login the second time, while cookie being replaced and only then you got logged in.
`

} onClick={async (e) => { e.preventDefault(); await mutateUser(fetchJson('/api/logout'), { method: 'POST' }); }} > Logout `

from iron-session.

vvo avatar vvo commented on May 18, 2024

Hey there, I believe this is now fixed, have a look at the updated example: 7ffc8bb

I cannot reproduce this bad behavior anymore.

from iron-session.

elie222 avatar elie222 commented on May 18, 2024

Facing this issue now.

import { NextApiRequest, NextApiResponse } from 'next';
import { withSessionRoute } from '@utils/iron-router';

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
    req.session.destroy();
    res.send({ ok: true });
};

export default withSessionRoute(handler);

We receive ok response but the session isn't destroyed when we try another api route straight after. Locally this works fine. On Vercel it doesn't for some reason.

from iron-session.

garryshield avatar garryshield commented on May 18, 2024

work out with this

// ...
await new Promise<void>((resolve, reject) => {
      req.session.destroy((err) => {
        if (err) {
          reject(err)
        } else {
          res.clearCookie('ACCESS_TOKEN', {
            domain: '.xxx.com'
          })
          res.clearCookie('REFRESH_TOKEN', {
            domain: '.xxx.com'
          })
          res.clearCookie('connect.sid', {
            domain: '.xxx.com'
          })

          resolve()
        }
      })
    })
// ...

from iron-session.

johnsmera avatar johnsmera commented on May 18, 2024

Version 13:
After 3 hours, changing the request to POST solved the problem. Shouldn't this have been more explicit?

from iron-session.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.