This commit is contained in:
parent
7926eb74b4
commit
8b2dbe9437
|
|
@ -163,11 +163,15 @@ async def google_callback(
|
|||
redirect_url = f"{frontend_url}/auth/callback?token={jwt_token}"
|
||||
return RedirectResponse(url=redirect_url)
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
class TokenExchangeRequest(BaseModel):
|
||||
code: str
|
||||
redirect_uri: str
|
||||
|
||||
@router.post("/google/token")
|
||||
async def exchange_google_token(
|
||||
code: str,
|
||||
redirect_uri: str,
|
||||
request: TokenExchangeRequest,
|
||||
db: AsyncSession = Depends(get_db)
|
||||
):
|
||||
"""
|
||||
|
|
@ -185,10 +189,10 @@ async def exchange_google_token(
|
|||
token_response = await client.post(
|
||||
GOOGLE_TOKEN_URL,
|
||||
data={
|
||||
"code": code,
|
||||
"code": request.code,
|
||||
"client_id": client_id,
|
||||
"client_secret": client_secret,
|
||||
"redirect_uri": redirect_uri,
|
||||
"redirect_uri": request.redirect_uri,
|
||||
"grant_type": "authorization_code",
|
||||
}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -51,7 +51,14 @@ function AuthCallbackContent() {
|
|||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json();
|
||||
throw new Error(errorData.detail || "Failed to exchange token");
|
||||
// Handle various error response formats
|
||||
const errorMessage =
|
||||
typeof errorData.detail === 'string' ? errorData.detail :
|
||||
typeof errorData.error === 'string' ? errorData.error :
|
||||
errorData.message ||
|
||||
JSON.stringify(errorData) ||
|
||||
"Failed to exchange token";
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
|
@ -59,7 +66,8 @@ function AuthCallbackContent() {
|
|||
router.replace("/");
|
||||
} catch (err: any) {
|
||||
console.error("Auth callback error:", err);
|
||||
setError(err.message || "Authentication failed");
|
||||
const msg = err.message || "Authentication failed";
|
||||
setError(typeof msg === 'string' ? msg : "Authentication failed");
|
||||
setIsProcessing(false);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue