-
-
Notifications
You must be signed in to change notification settings - Fork 53
update_user method lacks email_redirect_to option #727
Description
Bug report
The update_user method does not take into account the email_redirect_to or redirect_to option, which is present in supabase-js but oddly missing from the Python port. This is kinda necessary to support PKCE flow for email confirmation, as I use the redirect URL to confirm and exchange the token hash.
auth-py/supabase_auth/_sync/gotrue_client.py
Line 648 in d0740a1
| def update_user(self, attributes: UserAttributes) -> UserResponse: |
- I confirm this is a bug with Supabase, not with my own application.
- I confirm I have searched the Docs, GitHub Discussions, and Discord.
Describe the bug
email_redirect_to option is missing from update_user method, passing it as an attribute aslo does not work.
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
Something like this in fastapi does not work:
@router.post("/sign-up-anon-user", status_code=status.HTTP_201_CREATED)
async def convert_anon_user(
user: SignupSchema,
supabase: Annotated[AsyncClient, Depends(get_supabase_client)],
request: Request,
) -> dict:
"""Signs up a new user using the provided email and password.
Args:
user (SignupSchema): The user details to sign up.
supabase (AsyncClient): The Supabase client.
request (Request): FastAPI Request object.
Returns:
dict: A message indicating the sign-up was successful.
"""
try:
# Log the request details for debugging
logger.debug(f"scheme: {request.url.scheme}")
logger.debug(f"host: {request.headers.get('host')}")
logger.debug(f"x-forwarded-proto: {request.headers.get('x-forwarded-proto')}")
logger.debug(f"Redirect URL: {str(request.base_url).rstrip('/')}")
# 1. Check if anonymous user is present in the request
anon_user = await supabase.auth.get_session()
print(f"Anonymous user: {anon_user}")
if anon_user and anon_user.user and anon_user.user.is_anonymous:
logger.info(f"Anonymous user found: {anon_user.user.id}")
# 2. If so, convert it to a regular user
# If an anonymous user exists, we can convert it to a regular user
# updating the anonymous user with the new user details
# This will merge the anonymous user with the new user account.
# Note: If the user is already registered, this will throw an error
auth_response: AuthResponse = await supabase.auth.update_user(
{
"email": user.email,
"password": user.password,
# additional metadata about the user
"data": {"display_name": user.display_name},
# email_redirect_to is the URL the user will be redirected to after clicking the link in the email
"options": {
# email_redirect_to is the URL the user will be redirected to after clicking the link in the email
"email_redirect_to": str(request.base_url).rstrip("/"),
}
}
)
except Exception as e:
logger.error(f"Unhandled exception during sign in: {e}")
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="An error occurred during sign-up") from e
Expected behavior
email_redirect_to option should be accepted and correctly handled.
Screenshots
If applicable, add screenshots to help explain your problem.
System information
- OS: Fedora 42
- Browser (if applies) [e.g. chrome, safari]
- Version of supabase-py: 2.11.0
Additional context
Add any other context about the problem here.