nasr7322 commited on
Commit
2b1d84f
·
1 Parent(s): 5b2d925

updating auth returns

Browse files
Files changed (1) hide show
  1. auth/service/auth_service.py +5 -3
auth/service/auth_service.py CHANGED
@@ -1,7 +1,7 @@
1
  from sqlalchemy.orm import Session
2
  from fastapi import HTTPException, status
3
  from models import user as user_model
4
- from auth.domain.user_domain import AuthResponse
5
  import auth.auth_utils as auth_utils
6
 
7
  def signup_user(email: str, password: str, db: Session)->AuthResponse:
@@ -16,7 +16,8 @@ def signup_user(email: str, password: str, db: Session)->AuthResponse:
16
  db.refresh(new_user)
17
 
18
  token = auth_utils.create_access_token({"sub": new_user.email})
19
- return AuthResponse(access_token=token, user=new_user)
 
20
 
21
  def login_user(email: str, password: str, db: Session)->AuthResponse:
22
  db_user = db.query(user_model.User).filter(user_model.User.email == email).first()
@@ -24,7 +25,8 @@ def login_user(email: str, password: str, db: Session)->AuthResponse:
24
  raise HTTPException(status_code=401, detail="Invalid credentials")
25
 
26
  token = auth_utils.create_access_token({"sub": db_user.email})
27
- return AuthResponse(access_token=token, user=db_user)
 
28
 
29
  def auth(token: str, db: Session):
30
  payload = auth_utils.decode_access_token(token)
 
1
  from sqlalchemy.orm import Session
2
  from fastapi import HTTPException, status
3
  from models import user as user_model
4
+ from auth.domain.user_domain import AuthResponse, User
5
  import auth.auth_utils as auth_utils
6
 
7
  def signup_user(email: str, password: str, db: Session)->AuthResponse:
 
16
  db.refresh(new_user)
17
 
18
  token = auth_utils.create_access_token({"sub": new_user.email})
19
+ new_user_response = User(id=new_user.id, email=new_user.email)
20
+ return AuthResponse(access_token=token, user=new_user_response)
21
 
22
  def login_user(email: str, password: str, db: Session)->AuthResponse:
23
  db_user = db.query(user_model.User).filter(user_model.User.email == email).first()
 
25
  raise HTTPException(status_code=401, detail="Invalid credentials")
26
 
27
  token = auth_utils.create_access_token({"sub": db_user.email})
28
+ user_response = User(id=db_user.id, email=db_user.email)
29
+ return AuthResponse(access_token=token, user=user_response)
30
 
31
  def auth(token: str, db: Session):
32
  payload = auth_utils.decode_access_token(token)