Skip to content

Commit eddcde3

Browse files
committed
fix some typing issues and remove with provider when using fastapi_sso
1 parent 174c77c commit eddcde3

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

backend/app/auth/auth.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,14 @@ def verify_password(password: str, hashed_pass: str) -> bool:
7575
return password_context.verify(password, hashed_pass)
7676

7777

78-
async def authenticate_user(email: str, password: str):
78+
async def authenticate_user(email: str, password: str) -> models.User | None:
7979
user = await models.User.find_one({"email": email})
8080
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
8486
return user
8587

8688

@@ -112,7 +114,7 @@ async def _get_current_user(token):
112114
)
113115
try:
114116
payload = jwt.decode(token, settings.SECRET_KEY, algorithms=[ALGORITHM])
115-
userid: UUID = payload.get("sub")
117+
userid: UUID | None = payload.get("sub")
116118
if userid is None:
117119
raise credentials_exception
118120
token_data = schemas.TokenPayload(uuid=userid)

backend/app/routers/login.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async def login_access_token(form_data: OAuth2PasswordRequestForm = Depends()) -
3535
OAuth2 compatible token login, get an access token for future requests
3636
"""
3737
user = await authenticate_user(form_data.username, form_data.password)
38-
if not user:
38+
if user is None:
3939
raise HTTPException(status_code=400, detail="Incorrect email or password")
4040
elif not user.is_active:
4141
raise HTTPException(status_code=400, detail="Inactive user")
@@ -79,8 +79,7 @@ async def google_login(google_sso: GoogleSSO = Depends(get_google_sso)):
7979
"""
8080
Generate login url and redirect
8181
"""
82-
with google_sso:
83-
return await google_sso.get_login_redirect()
82+
return await google_sso.get_login_redirect()
8483

8584

8685
@router.get("/google/callback")
@@ -97,8 +96,7 @@ async def google_callback(
9796
)
9897

9998
# 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)
102100

103101
if google_user is None:
104102
raise HTTPException(

0 commit comments

Comments
 (0)