From 90485765806da0967c68dbc6f430c7d7db819639 Mon Sep 17 00:00:00 2001 From: Wu Clan Date: Thu, 14 Mar 2024 17:07:19 +0800 Subject: [PATCH] fix the callback interface return --- backend/app/api/v1/auth/github.py | 5 +---- backend/app/services/github_service.py | 3 ++- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/backend/app/api/v1/auth/github.py b/backend/app/api/v1/auth/github.py index e4114d25..2a8835e2 100644 --- a/backend/app/api/v1/auth/github.py +++ b/backend/app/api/v1/auth/github.py @@ -4,7 +4,6 @@ from fastapi_oauth20 import FastAPIOAuth20, GitHubOAuth20 from starlette.responses import RedirectResponse -from app.common.response.response_code import StandardResponseCode from app.services.github_service import github_service from backend.app.common.response.response_schema import ResponseModel, response_base from backend.app.core.conf import settings @@ -33,6 +32,4 @@ async def login_github( access_token = token['access_token'] user = await github_client.get_userinfo(access_token) data = await github_service.add_with_login(request, background_tasks, user) - if not data: - return RedirectResponse(url='/', status_code=StandardResponseCode.HTTP_302) - return await response_base.success(data=user) + return await response_base.success(data=data) diff --git a/backend/app/services/github_service.py b/backend/app/services/github_service.py index 933459a8..98e3e30f 100644 --- a/backend/app/services/github_service.py +++ b/backend/app/services/github_service.py @@ -5,6 +5,7 @@ from app.common import jwt from app.common.enums import LoginLogStatusType, UserSocialType +from app.common.exception.errors import AuthorizationError from app.common.redis import redis_client from app.core.conf import settings from app.crud.crud_user import user_dao @@ -23,7 +24,7 @@ async def add_with_login(request: Request, background_tasks: BackgroundTasks, us async with async_db_session.begin() as db: email = user['email'] if not email: - return None + raise AuthorizationError(msg='授权失败,GitHub 账户未绑定邮箱') username = user['login'] nickname = user['name'] sys_user = await user_dao.get_by_username(db, username)