Hammad712 commited on
Commit
f379782
·
verified ·
1 Parent(s): 78ac2af

Update service/auth_service.py

Browse files
Files changed (1) hide show
  1. service/auth_service.py +10 -10
service/auth_service.py CHANGED
@@ -54,29 +54,29 @@ class AuthService:
54
  raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(e))
55
 
56
  @staticmethod
57
- def get_google_oauth_url(final_redirect: str = None):
58
  try:
59
- # We append the final destination as a query parameter directly
60
- # to the callback URL that Supabase will use.
61
  base_callback = "https://hammad712-digitalbillboard.hf.space/auth/callback"
62
 
63
- # If final_redirect is 'digital-billboard://',
64
- # target becomes '.../callback?final_dest=digital-billboard://'
65
- target_redirect = base_callback
66
- if final_redirect:
67
- target_redirect = f"{base_callback}?final_dest={final_redirect}"
 
68
 
69
  response = supabase.auth.sign_in_with_oauth({
70
  "provider": "google",
71
  "options": {
72
- "redirect_to": target_redirect # This is the key change
73
  }
74
  })
75
  return response.url
76
  except Exception as e:
77
  logger.error("Failed to generate Google URL: %s", str(e))
78
  raise HTTPException(status_code=500, detail="OAuth Init Failed")
79
-
80
  @staticmethod
81
  def exchange_code(auth_code: str):
82
  try:
 
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
+ # This is your FastAPI backend callback URL
 
60
  base_callback = "https://hammad712-digitalbillboard.hf.space/auth/callback"
61
 
62
+ # If redirect_to is 'digital-billboard://', we bake it into the callback URL
63
+ # so it comes back to us in the 'google_callback' function later.
64
+ if redirect_to:
65
+ computed_callback = f"{base_callback}?final_dest={redirect_to}"
66
+ else:
67
+ computed_callback = base_callback
68
 
69
  response = supabase.auth.sign_in_with_oauth({
70
  "provider": "google",
71
  "options": {
72
+ "redirect_to": computed_callback # Supabase will return the user here
73
  }
74
  })
75
  return response.url
76
  except Exception as e:
77
  logger.error("Failed to generate Google URL: %s", str(e))
78
  raise HTTPException(status_code=500, detail="OAuth Init Failed")
79
+
80
  @staticmethod
81
  def exchange_code(auth_code: str):
82
  try: