Spaces:
Runtime error
Runtime error
Update service/auth_service.py
Browse files- service/auth_service.py +13 -7
service/auth_service.py
CHANGED
|
@@ -54,17 +54,23 @@ class AuthService:
|
|
| 54 |
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(e))
|
| 55 |
|
| 56 |
@staticmethod
|
| 57 |
-
def get_google_oauth_url():
|
| 58 |
try:
|
| 59 |
-
# Step 1: Tell Supabase to redirect
|
| 60 |
-
|
|
|
|
|
|
|
| 61 |
response = supabase.auth.sign_in_with_oauth({
|
| 62 |
"provider": "google",
|
| 63 |
"options": {
|
| 64 |
-
"redirect_to":
|
| 65 |
}
|
| 66 |
})
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
except Exception as e:
|
| 69 |
logger.error("Failed to generate Google URL: %s", str(e))
|
| 70 |
raise HTTPException(
|
|
@@ -77,10 +83,10 @@ class AuthService:
|
|
| 77 |
try:
|
| 78 |
# Step 2: Exchange the one-time code from Google for a valid Supabase session
|
| 79 |
response = supabase.auth.exchange_code_for_session({"auth_code": auth_code})
|
| 80 |
-
|
| 81 |
if not response.session:
|
| 82 |
raise ValueError("No session returned from Supabase")
|
| 83 |
-
|
| 84 |
return response.session.access_token
|
| 85 |
except Exception as e:
|
| 86 |
logger.error("Code exchange failed: %s", str(e))
|
|
|
|
| 54 |
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(e))
|
| 55 |
|
| 56 |
@staticmethod
|
| 57 |
+
def get_google_oauth_url(redirect_to: str = None):
|
| 58 |
try:
|
| 59 |
+
# Step 1: Tell Supabase where to redirect.
|
| 60 |
+
# If the router passes a specific URL, use it. Otherwise, fall back to the default.
|
| 61 |
+
target_redirect = redirect_to if redirect_to else f"{settings.API_URL}/auth/callback"
|
| 62 |
+
|
| 63 |
response = supabase.auth.sign_in_with_oauth({
|
| 64 |
"provider": "google",
|
| 65 |
"options": {
|
| 66 |
+
"redirect_to": target_redirect
|
| 67 |
}
|
| 68 |
})
|
| 69 |
+
|
| 70 |
+
# Since the router expects just the URL string (based on your auth_routes.py code),
|
| 71 |
+
# we should return just the string, not a dictionary.
|
| 72 |
+
return response.url
|
| 73 |
+
|
| 74 |
except Exception as e:
|
| 75 |
logger.error("Failed to generate Google URL: %s", str(e))
|
| 76 |
raise HTTPException(
|
|
|
|
| 83 |
try:
|
| 84 |
# Step 2: Exchange the one-time code from Google for a valid Supabase session
|
| 85 |
response = supabase.auth.exchange_code_for_session({"auth_code": auth_code})
|
| 86 |
+
|
| 87 |
if not response.session:
|
| 88 |
raise ValueError("No session returned from Supabase")
|
| 89 |
+
|
| 90 |
return response.session.access_token
|
| 91 |
except Exception as e:
|
| 92 |
logger.error("Code exchange failed: %s", str(e))
|