Skip to content

Commit

Permalink
update: access token에 user id, refresh 기능에 refresh token 반환 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
korjsh committed Dec 8, 2024
1 parent 53cadc7 commit 85cadc1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ __pycache__
*.env
build
dist
*.zip
*.zip
arch
10 changes: 3 additions & 7 deletions app/routers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@
import datetime
from passlib.context import CryptContext


router = APIRouter()
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")


# 암호화 객체를 가져오기

@router.post("/signup/", response_model=UserResponse)
def signup(user: UserCreate, db: Session = Depends(get_db)):
print("user:", user)
db_user = get_user_by_email(db, email=user.email)
if db_user:
raise HTTPException(status_code=400, detail="Email already registered")
Expand Down Expand Up @@ -47,10 +43,10 @@ def login(user: UserCreate, db: Session = Depends(get_db)):
access_token_expires = datetime.timedelta(minutes=15)
refresh_token_expires = datetime.timedelta(days=7)
access_token = create_access_token(
data={"sub": db_user.email}, expires_delta=access_token_expires
data={"id": db_user.id, "sub": db_user.email}, expires_delta=access_token_expires
)
refresh_token = create_refresh_token(
data={"sub": db_user.email}, expires_delta=refresh_token_expires
data={"id": db_user.id, "sub": db_user.email}, expires_delta=refresh_token_expires
)

return {"access_token": access_token, "refresh_token": refresh_token, "token_type": "bearer"}
Expand All @@ -76,4 +72,4 @@ def refresh_token(refresh_token: str, db: Session = Depends(get_db)):
data={"sub": db_user.email}, expires_delta=access_token_expires
)

return {"access_token": new_access_token, "token_type": "bearer"}
return {"access_token": new_access_token, "refresh_token": refresh_token, "token_type": "bearer"}

0 comments on commit 85cadc1

Please sign in to comment.