File tree Expand file tree Collapse file tree 2 files changed +10
-10
lines changed Expand file tree Collapse file tree 2 files changed +10
-10
lines changed Original file line number Diff line number Diff line change @@ -75,12 +75,14 @@ def verify_password(password: str, hashed_pass: str) -> bool:
75
75
return password_context .verify (password , hashed_pass )
76
76
77
77
78
- async def authenticate_user (email : str , password : str ):
78
+ async def authenticate_user (email : str , password : str ) -> models . User | None :
79
79
user = await models .User .find_one ({"email" : email })
80
80
if not user :
81
- return False
82
- if not verify_password (password , user .hashed_password ):
83
- return False
81
+ return None
82
+ if user .hashed_password is None or not verify_password (
83
+ password , user .hashed_password
84
+ ):
85
+ return None
84
86
return user
85
87
86
88
@@ -112,7 +114,7 @@ async def _get_current_user(token):
112
114
)
113
115
try :
114
116
payload = jwt .decode (token , settings .SECRET_KEY , algorithms = [ALGORITHM ])
115
- userid : UUID = payload .get ("sub" )
117
+ userid : UUID | None = payload .get ("sub" )
116
118
if userid is None :
117
119
raise credentials_exception
118
120
token_data = schemas .TokenPayload (uuid = userid )
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ async def login_access_token(form_data: OAuth2PasswordRequestForm = Depends()) -
35
35
OAuth2 compatible token login, get an access token for future requests
36
36
"""
37
37
user = await authenticate_user (form_data .username , form_data .password )
38
- if not user :
38
+ if user is None :
39
39
raise HTTPException (status_code = 400 , detail = "Incorrect email or password" )
40
40
elif not user .is_active :
41
41
raise HTTPException (status_code = 400 , detail = "Inactive user" )
@@ -79,8 +79,7 @@ async def google_login(google_sso: GoogleSSO = Depends(get_google_sso)):
79
79
"""
80
80
Generate login url and redirect
81
81
"""
82
- with google_sso :
83
- return await google_sso .get_login_redirect ()
82
+ return await google_sso .get_login_redirect ()
84
83
85
84
86
85
@router .get ("/google/callback" )
@@ -97,8 +96,7 @@ async def google_callback(
97
96
)
98
97
99
98
# Get user details from Google
100
- with google_sso :
101
- google_user = await google_sso .verify_and_process (request )
99
+ google_user = await google_sso .verify_and_process (request )
102
100
103
101
if google_user is None :
104
102
raise HTTPException (
You can’t perform that action at this time.
0 commit comments