Skip to content

fix: update Supabase token retrieval to remove unnecessary await #2166

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions py/core/providers/auth/supabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async def decode_token(self, token: str) -> TokenData:
token = token[7:]

# Get Supabase token information
auth_response = await self.supabase.auth.get_user(token)
auth_response = self.supabase.auth.get_user(token)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure consistency in using await for get_user. Other methods (e.g., user()) await this call, so confirm if get_user is sync. If it’s async, removing await is a bug.

Suggested change
auth_response = self.supabase.auth.get_user(token)
auth_response = await self.supabase.auth.get_user(token)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@suysoftware can you confirm if this is a valid comment? Just want to verify that everything is working for you and then I will merge. Thanks!


if not auth_response or not auth_response.user:
raise R2RException(status_code=401, message="Invalid token")
Expand Down Expand Up @@ -147,7 +147,7 @@ async def verify_email(
async def login(self, email: str, password: str) -> dict[str, Token]:
# Use Supabase client to authenticate user and get tokens
try:
response = await self.supabase.auth.sign_in_with_password(
response = self.supabase.auth.sign_in_with_password(
{"email": email, "password": password}
)
# Correct access method - token information is found in response.session
Expand Down Expand Up @@ -177,7 +177,7 @@ async def refresh_access_token(
) -> dict[str, Token]:
# Use Supabase client to refresh access token
try:
response = await self.supabase.auth.refresh_session(refresh_token)
response = self.supabase.auth.refresh_session(refresh_token)
if response.session:
new_access_token = response.session.access_token
new_refresh_token = response.session.refresh_token
Expand All @@ -202,7 +202,7 @@ async def refresh_access_token(
async def user(self, token: str = Depends(oauth2_scheme)) -> User:
# Use Supabase client to get user details from token
try:
auth_response = await self.supabase.auth.get_user(token)
auth_response = self.supabase.auth.get_user(token)
if auth_response.user:
user_data = auth_response.user
return User(
Expand Down Expand Up @@ -236,11 +236,11 @@ async def change_password(
# Use Supabase client to update user password
try:
# First, we log in with the current password to verify the user
await self.supabase.auth.sign_in_with_password(
self.supabase.auth.sign_in_with_password(
{"email": user.email, "password": current_password}
)
# Then we update the password
await self.supabase.auth.update_user({"password": new_password})
self.supabase.auth.update_user({"password": new_password})
return {"message": "Password changed successfully"}
except Exception as e:
logger.error(f"Password change error: {str(e)}")
Expand Down Expand Up @@ -270,7 +270,7 @@ async def request_password_reset(self, email: str) -> dict[str, str]:
# Use the default URL
redirect_url = "https://app.sciphi.ai/auth/login"
# Send the password reset email and use the custom redirect URL
await self.supabase.auth.reset_password_for_email(
self.supabase.auth.reset_password_for_email(
email, options={"redirect_to": redirect_url}
)
# Return a success message for security reasons
Expand All @@ -294,7 +294,7 @@ async def confirm_password_reset(
async def logout(self, token: str) -> dict[str, str]:
try:
# Logout the user
await self.supabase.auth.sign_out()
self.supabase.auth.sign_out()
return {"message": "Logged out successfully"}
except Exception as e:
logger.error(f"Logout error: {str(e)}")
Expand Down
Loading