Skip to content

Commit ed8b758

Browse files
authored
Bug Fix for Token Update Issue and Addition of Static Methods (#27)
* 🐛 Made sure to return updated user. Now the tokens are successfully being removed from database user refresh_tokens array * 🔨 Used static methods for some CRUD user methods.
1 parent 0cf8316 commit ed8b758

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

{{cookiecutter.project_slug}}/backend/app/app/api/deps.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ async def get_refresh_user(
9898
detail="Could not validate credentials",
9999
)
100100
await crud.token.remove(db, db_obj=token_obj)
101-
return user
101+
102+
# Make sure to revoke all other refresh tokens
103+
return await crud.user.get(id=token_data.sub)
102104

103105

104106
async def get_current_active_user(

{{cookiecutter.project_slug}}/backend/app/app/crud/crud_user.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,19 @@ async def toggle_user_state(self, db: AgnosticDatabase, *, obj_in: Union[UserUpd
7777
return None
7878
return await self.update(db=db, db_obj=db_obj, obj_in=obj_in)
7979

80+
@staticmethod
8081
def has_password(self, user: User) -> bool:
81-
if user.hashed_password:
82-
return True
83-
return False
82+
return user.hashed_password is not None
8483

84+
@staticmethod
8585
def is_active(self, user: User) -> bool:
8686
return user.is_active
8787

88+
@staticmethod
8889
def is_superuser(self, user: User) -> bool:
8990
return user.is_superuser
9091

92+
@staticmethod
9193
def is_email_validated(self, user: User) -> bool:
9294
return user.email_validated
9395

0 commit comments

Comments
 (0)