Update password (not reset password page)

Hi everyone 👋 I'm working on a password update feature using Supabase Auth in my Next.js app. The password update itself works perfectly — Supabase updates the password and I can log in again with the new one. However, the current session becomes invalid right after the password change, but Supabase doesn't automatically sign out the user. So on the frontend, the user still appears logged in, but any API calls fail with “Invalid JWT”. I’ve tried calling supabase.auth.signOut() or refreshing the session after the update, but it doesn’t seem to take effect — the button stays on “Updating...” and the session event log still shows “Session active”. How can I properly handle this situation and force a clean logout (or session refresh) right after a successful password update? Thanks a lot for your help 🙏
No description
9 Replies
chamath
chamath•2w ago
Hey!
Angélique<FreeDev>
Angélique<FreeDev>OP•2w ago
we have found the solution, I have change this line : supabase.auth.updateUser({ password: formData.newPassword, }); Before, I only get the error from the response. Now, the update password work and the user is redirect on the login page
chamath
chamath•2w ago
Awesome, glad you got it working! Just to clarify for anyone else who might have this issue - so the problem was that you weren't destructuring the full response from updateUser() function? You changed this line: const { error } = await supabase.auth.updateUser(...) to: { data, error } = ... to get data as well? Did you by chance also add: await supabase.auth.signOut(); to the now working code? Or is it working without it?
Angélique<FreeDev>
Angélique<FreeDev>OP•2w ago
From what I understand, supabase automatically invalidates the session so I had to redirect to the login page. I tried putting signOut but it didn't work (in fact, I tried a lot of things lol). With a setTimeOut and a message to the user, I manually redirect to the login page.
chamath
chamath•2w ago
Ah i see. As long as you got it working. Let us know if you run into any other issues. Happy coding! au revoir!
Angélique<FreeDev>
Angélique<FreeDev>OP•2w ago
Thanks
chamath
chamath•2w ago
Hey, if you do not mind, can I have a look at the updated same "onSubmit" that now works just to gain a better understanding?
silentworks
silentworks•2w ago
I have a fully working example repo here with this auth flow https://github.com/silentworks/supabase-by-example/tree/main/nextjs
Angélique<FreeDev>
Angélique<FreeDev>OP•2w ago
No description

Did you find this page helpful?