File tree 4 files changed +9
-6
lines changed
Filter options
4 files changed +9
-6
lines changed
Original file line number Diff line number Diff line change
1
+ import uuid
1
2
from .database import Base
2
3
from sqlalchemy import TIMESTAMP , Column , String , Boolean , text
3
4
from sqlalchemy .dialects .postgresql import UUID
4
5
5
6
6
7
class User (Base ):
7
8
__tablename__ = 'users'
8
- id = Column (UUID , primary_key = True , nullable = False ,
9
- server_default = text ( "uuid_generate_v4()" ) )
9
+ id = Column (UUID ( as_uuid = True ) , primary_key = True , nullable = False ,
10
+ default = uuid . uuid4 )
10
11
name = Column (String , nullable = False )
11
12
email = Column (String , unique = True , nullable = False )
12
13
password = Column (String , nullable = False )
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ class Settings(BaseModel):
16
16
authjwt_token_location : set = {'cookies' , 'headers' }
17
17
authjwt_access_cookie_key : str = 'access_token'
18
18
authjwt_refresh_cookie_key : str = 'refresh_token'
19
+ authjwt_cookie_csrf_protect : bool = False
19
20
authjwt_public_key : str = base64 .b64decode (
20
21
settings .JWT_PUBLIC_KEY ).decode ('utf-8' )
21
22
authjwt_private_key : str = base64 .b64decode (
Original file line number Diff line number Diff line change @@ -61,11 +61,11 @@ def login(payload: schemas.LoginUserSchema, response: Response, db: Session = De
61
61
62
62
# Create access token
63
63
access_token = Authorize .create_access_token (
64
- subject = user .id , expires_time = timedelta (minutes = ACCESS_TOKEN_EXPIRES_IN ))
64
+ subject = str ( user .id ) , expires_time = timedelta (minutes = ACCESS_TOKEN_EXPIRES_IN ))
65
65
66
66
# Create refresh token
67
67
refresh_token = Authorize .create_refresh_token (
68
- subject = user .id , expires_time = timedelta (minutes = REFRESH_TOKEN_EXPIRES_IN ))
68
+ subject = str ( user .id ) , expires_time = timedelta (minutes = REFRESH_TOKEN_EXPIRES_IN ))
69
69
70
70
# Store refresh and access tokens in cookie
71
71
response .set_cookie ('access_token' , access_token , ACCESS_TOKEN_EXPIRES_IN * 60 ,
@@ -94,7 +94,7 @@ def refresh_token(response: Response, request: Request, Authorize: AuthJWT = Dep
94
94
raise HTTPException (status_code = status .HTTP_401_UNAUTHORIZED ,
95
95
detail = 'The user belonging to this token no logger exist' )
96
96
access_token = Authorize .create_access_token (
97
- subject = user_id , expires_time = timedelta (minutes = ACCESS_TOKEN_EXPIRES_IN ))
97
+ subject = str ( user . id ) , expires_time = timedelta (minutes = ACCESS_TOKEN_EXPIRES_IN ))
98
98
except Exception as e :
99
99
error = e .__class__ .__name__
100
100
if error == 'MissingTokenError' :
Original file line number Diff line number Diff line change 1
1
from datetime import datetime
2
+ import uuid
2
3
from pydantic import BaseModel , EmailStr , constr
3
4
4
5
@@ -24,6 +25,6 @@ class LoginUserSchema(BaseModel):
24
25
25
26
26
27
class UserResponse (UserBaseSchema ):
27
- id : str
28
+ id : uuid . UUID
28
29
created_at : datetime
29
30
updated_at : datetime
You can’t perform that action at this time.
0 commit comments