Refresh Token set up
Browse files- auth/services.py +11 -7
auth/services.py
CHANGED
@@ -54,18 +54,22 @@ def _verify_user_access(user: User):
|
|
54 |
)
|
55 |
return True
|
56 |
|
57 |
-
async def _get_user_token(user:User, refresh_token: bool = False):
|
58 |
payload = {"id": user.id, "sub": user.email}
|
59 |
|
60 |
access_token_expiry = timedelta(minutes=settings.ACCESS_TOKEN_EXPIRE_MINUTES)
|
61 |
-
|
62 |
access_token = await create_access_token(data=payload, expiry=access_token_expiry)
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
|
|
65 |
|
66 |
return TokenResponse(
|
67 |
access_token=access_token,
|
68 |
-
refresh_token=
|
69 |
-
expires_in=
|
70 |
-
|
|
|
71 |
|
|
|
54 |
)
|
55 |
return True
|
56 |
|
57 |
+
async def _get_user_token(user: User, refresh_token: bool = False):
|
58 |
payload = {"id": user.id, "sub": user.email}
|
59 |
|
60 |
access_token_expiry = timedelta(minutes=settings.ACCESS_TOKEN_EXPIRE_MINUTES)
|
|
|
61 |
access_token = await create_access_token(data=payload, expiry=access_token_expiry)
|
62 |
+
|
63 |
+
# Ensure refresh_token is a string or None
|
64 |
+
if refresh_token:
|
65 |
+
refresh_token_value = await create_refresh_token(data=payload)
|
66 |
+
else:
|
67 |
+
refresh_token_value = None
|
68 |
|
69 |
return TokenResponse(
|
70 |
access_token=access_token,
|
71 |
+
refresh_token=refresh_token_value, # This is now a string or None
|
72 |
+
expires_in=access_token_expiry.seconds
|
73 |
+
)
|
74 |
+
|
75 |
|