Skip to content
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

Event Listener #574

Open
fooyongyan opened this issue Jul 19, 2023 · 1 comment
Open

Event Listener #574

fooyongyan opened this issue Jul 19, 2023 · 1 comment

Comments

@fooyongyan
Copy link

Hi,

I am currently using cookies to store my token information, so that I can persist and retain user login information, even when they leave the page. I would like to check, if there is any way I can receive or implement an event listener on active pages, so that I can handle under the circumstances where my cookie had expired or replaced?

@martinIvovIv
Copy link

You could use a middleware that checks the validity of the cookie.

import { parseCookies } from 'nookies'

export function middleware(request: NextRequest) {
  if (!parseCookies({ request}).tokenInformation || isTokenExpiredOrReplaced(parseCookies({ request}).tokenInformation)) {
     handleCircumstances()
  }

   return NextResponse.next()
}

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

No branches or pull requests

2 participants