DEV Community

Discussion on: Next.js Authentication - JWT Refresh Token Rotation with NextAuth.js

Collapse
 
htissink profile image
Henrick Tissink

Absolutely excellent article Mateusz! :D what a lifesaver! ...just a small heads up :) not sure if intentional - the hook you create is called useAuth but after that, you mention const isAuthenticated = useWithAuth(true) - maybe a small typo?

Collapse
 
mabaranowski profile image
Mateusz Baranowski

Yeh, a typo, it should be useAuth. Fixed it, thank you Henrick! :)

Collapse
 
htissink profile image
Henrick Tissink

useAuth(true) - could you explain how you pass in the boolean param?

Thread Thread
 
mabaranowski profile image
Mateusz Baranowski • Edited

I originally used it to decide if I want to be redirected or not:

export default function useAuth(shouldRedirect) {
  ...
  signOut({ callbackUrl: '/login', redirect: shouldRedirect });
  ...
}
Enter fullscreen mode Exit fullscreen mode

When the user is on the unprotected page, and for whatever reason his token expires, I want to silently log him out, without redirecting him to the login page.

I'll update the example code with this redirect flag :)

Thread Thread
 
htissink profile image
Henrick Tissink

That functionality sounds great :) thanks for updating!