Skip to content

supabase.auth.sign_in_with_otp with phone login throws error #321

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

Closed
hgseo16 opened this issue Apr 7, 2023 · 10 comments
Closed

supabase.auth.sign_in_with_otp with phone login throws error #321

hgseo16 opened this issue Apr 7, 2023 · 10 comments

Comments

@hgseo16
Copy link
Contributor

hgseo16 commented Apr 7, 2023

Describe the bug
While the following function supabase.auth.sign_in_with_otp(params={"phone": phone, "token": verification_code, "type": "sms"}) successfully sends an OTP to the phone number described, the request returns the following error.

.
.
.
  File "/Users/zzan/Desktop/repositories/zzan-backend-fastapi/./app/routers/users.py", line 23, in post_signin_phone
    data = supabase.auth.sign_in_with_otp(credentials={"phone": phone})
  File "/Users/zzan/Desktop/repositories/zzan-backend-fastapi/venv/lib/python3.9/site-packages/gotrue/_sync/gotrue_client.py", line 299, in sign_in_with_otp
    return self._request(
  File "/Users/zzan/Desktop/repositories/zzan-backend-fastapi/venv/lib/python3.9/site-packages/gotrue/_sync/gotrue_base_api.py", line 119, in _request
    raise handle_exception(e)
gotrue.errors.AuthRetryableError: 5 validation errors for User
id
  field required (type=value_error.missing)
app_metadata
  field required (type=value_error.missing)
user_metadata
  field required (type=value_error.missing)
aud
  field required (type=value_error.missing)
created_at
  field required (type=value_error.missing)

To Reproduce

from supabase import create_client, Client

url: str = "SUPABASE_API_URL"
key: str = "SUPABASE_API_KEY"
supabase: Client = create_client(url, key)

phone: str = "PHONE_NUMBER_WITH_COUNTRY_CODE"

data = supabase.auth.sign_in_with_otp(credentials={"phone": phone})
print(data)

Expected behavior
Should return an AuthResponse class.

class AuthResponse(BaseModel):
    user: Union[User, None] = None
    session: Union[Session, None] = None

Screenshots
Screenshot 2023-04-07 at 5 47 33 PM

Environment (please complete the following information):

  • Python: 3.9.6
  • OS: macOS Ventura (v. 13.2.1)

Additional context
It seems that there is an issue occurring when the sign_in_with_otp function is called. The problem seems to be happening when the function tries to return the result of self._request(...), which is a function call in the gotrue_base_api.py module. When the _request function is called, the result variable is an empty dictionary {} which may be causing an issue during the parse_auth_response function invocation in the gotrue package.

Let me know what you guys think! I would love to try to help debug this issue as well.

@pereira-software
Copy link

Running into a similar problem using email to sign up

    def create_user(self, email: str, password: str, app_url: str) -> dict:
        session = self.supabase.auth.sign_in_with_otp({"email": email, "options":{"email_redirect_to": app_url}})

Calling this function causes the same error in my app

5 validation errors for User
id
  field required (type=value_error.missing)
app_metadata
  field required (type=value_error.missing)
user_metadata
  field required (type=value_error.missing)
aud
  field required (type=value_error.missing)
created_at
  field required (type=value_error.missing)

An email is still sent to the email and the magic link does work with a user still being created in the database.
Any attempt at singing on again with the same user once verified throws the same error.
Is there a setting in my Supabase dashboard that needs to be updated?

Details

  • Flask Project
  • Python 3.11.2
  • OS: Microsoft Windows 10 v10.0.19045

@blackbera
Copy link

Hey @hgseo16
I see you provided a fix for this? When will it be merged? Just curious

@hgseo16
Copy link
Contributor Author

hgseo16 commented May 22, 2023

Hi @atj3097,

I don't have merge access to the PR I made so I notified the maintainer of gotrue-py repository. Thank you for reminding me of this!

@kunal-sharda
Copy link

kunal-sharda commented Jun 29, 2023

@hgseo16 do you know why this error might still be happening for email? sorry for reviving this thread, but currently going through this problem.

edit, forgot to force update my version, sorry for the ping.

@J0
Copy link
Contributor

J0 commented Sep 15, 2023

Hey team,

Can I check if the issue perists?

@kunal-sharda do you mind sharing the code snippet for email? I suspect the pydantic models haven't been updated for v2.

@J0 J0 transferred this issue from supabase/supabase-py Sep 15, 2023
@silentworks
Copy link
Contributor

Closing this as fixed as there hasn't been any reports of this issue persisting in newer versions of the library.

@lucas-vitrus
Copy link

Getting the same error..

AuthRetryableError
gotrue.errors.AuthRetryableError: 5 validation errors for User
id
  Field required [type=missing, input_value={'message_id': 'SM724b22e...ecc8ff615e0406e1d92cf8'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.3/v/missing
app_metadata
  Field required [type=missing, input_value={'message_id': 'SM724b22e...ecc8ff615e0406e1d92cf8'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.3/v/missing
user_metadata
  Field required [type=missing, input_value={'message_id': 'SM724b22e...ecc8ff615e0406e1d92cf8'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.3/v/missing
aud
  Field required [type=missing, input_value={'message_id': 'SM724b22e...ecc8ff615e0406e1d92cf8'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.3/v/missing
created_at
  Field required [type=missing, input_value={'message_id': 'SM724b22e...ecc8ff615e0406e1d92cf8'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.3/v/missing

Traceback (most recent call last)
File "/Users/lucascassiano/.local/share/virtualenvs/gateway-server-1zd7_S6J/lib/python3.10/site-packages/gotrue/_sync/gotrue_base_api.py", line 116, in _request
return xform(result)
File "/Users/lucascassiano/.local/share/virtualenvs/gateway-server-1zd7_S6J/lib/python3.10/site-packages/gotrue/helpers.py", line 66, in parse_auth_response
user = model_validate(User, user_data) if user_data else None
File "/Users/lucascassiano/.local/share/virtualenvs/gateway-server-1zd7_S6J/lib/python3.10/site-packages/gotrue/helpers.py", line 28, in model_validate
return model.model_validate(contents)
File "/Users/lucascassiano/.local/share/virtualenvs/gateway-server-1zd7_S6J/lib/python3.10/site-packages/pydantic/main.py", line 504, in model_validate
return cls.__pydantic_validator__.validate_python(
During handling of the above exception, another exception occurred:
File "/Users/lucascassiano/.local/share/virtualenvs/gateway-server-1zd7_S6J/lib/python3.10/site-packages/flask/app.py", line 2213, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/lucascassiano/.local/share/virtualenvs/gateway-server-1zd7_S6J/lib/python3.10/site-packages/flask/app.py", line 2193, in wsgi_app
response = self.handle_exception(e)
File "/Users/lucascassiano/.local/share/virtualenvs/gateway-server-1zd7_S6J/lib/python3.10/site-packages/flask_cors/extension.py", line 176, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "/Users/lucascassiano/.local/share/virtualenvs/gateway-server-1zd7_S6J/lib/python3.10/site-packages/flask/app.py", line 2190, in wsgi_app
response = self.full_dispatch_request()
File "/Users/lucascassiano/.local/share/virtualenvs/gateway-server-1zd7_S6J/lib/python3.10/site-packages/flask/app.py", line 1486, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/lucascassiano/.local/share/virtualenvs/gateway-server-1zd7_S6J/lib/python3.10/site-packages/flask_cors/extension.py", line 176, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "/Users/lucascassiano/.local/share/virtualenvs/gateway-server-1zd7_S6J/lib/python3.10/site-packages/flask/app.py", line 1484, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/lucascassiano/.local/share/virtualenvs/gateway-server-1zd7_S6J/lib/python3.10/site-packages/flask/app.py", line 1469, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
File "/Users/lucascassiano/Documents/GitHub/vitrus-ai-vision/gateway-server/./src/main.py", line 330, in user_sign_in
data = supabase.auth.sign_in_with_otp({'phone': phone_number})
File "/Users/lucascassiano/.local/share/virtualenvs/gateway-server-1zd7_S6J/lib/python3.10/site-packages/gotrue/_sync/gotrue_client.py", line 306, in sign_in_with_otp
return self._request(
File "/Users/lucascassiano/.local/share/virtualenvs/gateway-server-1zd7_S6J/lib/python3.10/site-packages/gotrue/_sync/gotrue_base_api.py", line 118, in _request
raise handle_exception(e)
gotrue.errors.AuthRetryableError: 5 validation errors for User
id
Field required [type=missing, input_value={'message_id': 'SM724b22e...ecc8ff615e0406e1d92cf8'}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.3/v/missing
app_metadata
Field required [type=missing, input_value={'message_id': 'SM724b22e...ecc8ff615e0406e1d92cf8'}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.3/v/missing
user_metadata
Field required [type=missing, input_value={'message_id': 'SM724b22e...ecc8ff615e0406e1d92cf8'}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.3/v/missing
aud
Field required [type=missing, input_value={'message_id': 'SM724b22e...ecc8ff615e0406e1d92cf8'}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.3/v/missing
created_at
Field required [type=missing, input_value={'message_id': 'SM724b22e...ecc8ff615e0406e1d92cf8'}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.3/v/missing
The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error.
To switch between the interactive traceback and the plaintext one, you can click on the "Traceback" headline. From the text traceback you can also create a paste of it. For code execution mouse-over the frame you want to debug and click on the console icon on the right side.

You can execute arbitrary Python code in the stack frames and there are some extra helpers available for introspection:

dump() shows all variables in the frame
dump(obj) dumps all that's known about the object
Brought to you by DON'T PANIC, your friendly Werkzeug powered traceback interpreter.

@J0
Copy link
Contributor

J0 commented Nov 10, 2023

Ah yeah this is probably from the new message_id field - let's track this on a separate issue

@athon-millane
Copy link

@J0 I'm still encountering the issue as well - was the separate issue ever created?

@J0
Copy link
Contributor

J0 commented Jan 17, 2024

Hey @athon-millane,

I don't think it was, sorry about that. Thanks for flagging this

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

8 participants