supabase / auth

A JWT based API for managing users and issuing JWT tokens
https://supabase.com/docs/guides/auth
MIT License
1.53k stars 372 forks source link

Can't verify email change OTP code - "User not found" #897

Closed nicolantean closed 1 year ago

nicolantean commented 1 year ago

Bug report

Describe the bug

After creating a user with the signInWithOtp method using a phone and then adding an email for that user using updateUser, I get a User not found error while calling verifyOTP method with the email added before.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Create a user using SupabaseClient.auth.signInWithOtp(phone: "XXXXXXXX");
  2. Verify the phone with SupabaseClient.auth.verifyOTP( phone: "XXXXXXXX", token: "XXXX", type: OtpType.sms);
  3. Add an email for the user calling SupabaseClient.auth.updateUser(UserAttributes(phone: "XXXXXXXX", email: "XXX@XXX.XX"));
  4. Verify the OTP code sent to the email for confirmation using SupabaseClient.auth.verifyOTP(email: "XXX@XXX.XX", token: "XXXX", type: OtpType.emailChange);
  5. See an exception AuthException(message: User not found, statusCode: 404)

Expected behavior

As the users table on the auth schema has email_change and email_change_sent_at values updated with the email added before, the verifyOTP has to find the email and respond successfully.

System information

Additional context

Sometimes after updating the same email multiple times on the same user I could verify it successfully but only a few times.

mirland commented 1 year ago

Hi @dshukertjr @kangmingtay, we are a bit stuck with that. Do you have any news? Can we help with something?

Thanks for the hard work and the great tool!

kangmingtay commented 1 year ago

Hey @nicolantean and @mirland, I've made a PR to fix this bug already. Thanks for reporting this!

nicolantean commented 1 year ago

Thank you so much @kangmingtay for the fix! I've tried the same flow but it is still not working. What do I have to do to use the latest version of gotrue on my flutter project? Because I couldn't find the gotrue version that is using my project.

mirland commented 1 year ago

Hi, @kangmingtay thanks for the fix! I'm currently testing it again and I'm having the same issue. How can I update supabase to fix the issue? Do you know if this fix has already been released on Supabase? I'm not finding documentation about it

mirland commented 1 year ago

Hi @kangmingtay @dshukertjr, We have tested it again and it's still not working. Can you give me support? Should we do something on our side to upgrade this module in Supabase? I couldn't find any documentation about that. Right now it's blocking us from releasing our product to production.

I also think this issue shouldn't be closed until the fix is validated, can you reopen it, please?

Thanks again for the hard work, great product, and for your effort!

mirland commented 1 year ago

We tried it again, paused the server, and resumed it. After that, it starts working! We have tried it before but it didn't work, maybe the changes were not in prod. I don't know. We tested it a couple of times now and it seems to be working. Thanks, you can close the issue

kangmingtay commented 1 year ago

hey @mirland, apologies for the late reply but in the future, it would be great if you can contact us through support. It's quite challenging to keep up with the github notifications and we have an excellent support team that helps with making sure that your questions get answered in time.

mirland commented 1 year ago

Yes, thanks! The support team gave me the suggestion! I tried it again and it worked Thanks again