Make google auth work
This commit is contained in:
parent
ef4257edfd
commit
2151d5aa5d
2 changed files with 15 additions and 19 deletions
|
|
@ -1,7 +1,8 @@
|
|||
from fastapi import Depends, HTTPException, status
|
||||
from fastapi import Depends, HTTPException, status, Request
|
||||
from fastapi.routing import APIRouter
|
||||
from fastapi.encoders import jsonable_encoder
|
||||
from fastapi.security import OAuth2PasswordBearer
|
||||
from fastapi.responses import RedirectResponse
|
||||
from supabase import Client
|
||||
from app.config import settings
|
||||
from jose import JWTError, jwt
|
||||
|
|
@ -59,7 +60,7 @@ async def login_with_google(supabase: Client = Depends(get_supabase)):
|
|||
response = supabase.auth.sign_in_with_oauth({
|
||||
"provider": "google",
|
||||
"options": {
|
||||
"redirect_to": "https://mhcafqvzbrrwvahpvvzd.supabase.co/auth/v1/callback"
|
||||
"redirect_to": "http://localhost:8000/auth/callback"
|
||||
}
|
||||
})
|
||||
return {"auth_url": response.url}
|
||||
|
|
@ -69,6 +70,14 @@ async def login_with_google(supabase: Client = Depends(get_supabase)):
|
|||
detail=str(e)
|
||||
)
|
||||
|
||||
@router.get("/callback")
|
||||
async def google_callback(request: Request, supabase: Client = Depends(get_supabase)):
|
||||
code = request.query_params.get("code")
|
||||
if not code:
|
||||
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Missing authorization code")
|
||||
|
||||
supabase.auth.exchange_code_for_session({"auth_code": code})
|
||||
return RedirectResponse(url="http://localhost:5173")
|
||||
|
||||
@router.post("/logout")
|
||||
async def logout(user=Depends(get_current_user_required), supabase: Client = Depends(get_supabase)):
|
||||
|
|
|
|||
|
|
@ -3,26 +3,13 @@ from fastapi.security import OAuth2PasswordBearer
|
|||
from typing import Optional
|
||||
from supabase import Client
|
||||
from app.config import settings
|
||||
|
||||
from supabase import create_client
|
||||
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="auth/login", auto_error=False)
|
||||
|
||||
supabase_client = create_client(settings.supabase_url, settings.supabase_key)
|
||||
|
||||
def get_supabase() -> Client:
|
||||
from supabase import create_client
|
||||
|
||||
# Temporary hardcoded values
|
||||
import os
|
||||
|
||||
|
||||
# Access environment variables
|
||||
# Debugging purpose
|
||||
|
||||
url = settings.supabase_url
|
||||
key = settings.supabase_key # From Supabase dashboard
|
||||
|
||||
# print("[HARDCODED] URL:", url)
|
||||
# print("[HARDCODED] Key:", key[:10] + "...")
|
||||
|
||||
return create_client(url, key)
|
||||
return supabase_client
|
||||
|
||||
# Updated current user dependency
|
||||
async def get_user_from_token(
|
||||
|
|
|
|||
Loading…
Reference in a new issue