0

I am working on project using Next JS + NextAuth package. For user authentication we are using NextAuth with Custom Credentials provider. I am making a sign in REst API request to Firebase to get the user logged in and saving all necessary bits like Firebase tokens(access and refresh) in JWT.

The flow works.

Where i am stuck: Changing user password. Password change is pretty straight forward using firebase client SDK. But I am using Firebase API: https://firebase.google.com/docs/reference/rest/auth#section-change-password the flow to change password requires: Provide latest access token in API request above. If the latest Access token is not provided, the API would send back error like: TOKEN TOO OLD or RE AUTHENTICATE So this to work, we need to reauthenticate the user prior to making that change password request.

What I have managed to do:

At this point i am stuck: Refreshing the JWT using Next Auth; as soon as the user is re-signed-in and again when password is changed and new access token is sent back from Firebase.

When I try to refresh the JWT with new access token (etc) token using NextAuth client side callback: https://next-auth.js.org/tutorials/refresh-token-rotation The application breaks due to access tokens are not synced on JWT and on firebase.

Questions: Is my flow correct changing the user password? Is there better way of doing this?

Any help is appreciated. Thanks

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Kamran
  • 1
  • 1
  • 1
    Yes, that's correct. You should ask users to provide credentials for reauthentication. Can you share your code that you are using to set the JWT token first time user logs in? You could perhaps use the same flow. – Dharmaraj Sep 08 '22 at 11:37

0 Answers0