-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
## Summary Fixes #3516 ### Time to review: __3 mins__ ## Changes proposed Add a utility method for fetching the user token session to handle type checking issues. ## Context for reviewers This removes the need to have `api_jwt_auth.current_user # type: ignore` in every place we fetch the user. Note that we have to do some sort of type ignore/cast because the type is `None | Any` on `current_user` as it's just whatever you return from the decode_token method. ## Additional information All tests continue to pass which rely on fetching this
- Loading branch information
Showing
3 changed files
with
27 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from typing import cast | ||
|
||
from apiflask import HTTPTokenAuth | ||
|
||
from src.db.models.user_models import UserTokenSession | ||
|
||
|
||
class JwtUserHttpTokenAuth(HTTPTokenAuth): | ||
|
||
def get_user_token_session(self) -> UserTokenSession: | ||
"""Wrapper method around the current_user value to handle type issues | ||
Note that this value gets set based on whatever is returned from the method | ||
you configure for @<your JwtUserHttpTokenAuth obj>.verify_token | ||
""" | ||
return cast(UserTokenSession, self.current_user) |