| 73 | return user |
| 74 | |
| 75 | def create_access_token(data: dict, expires_delta: Optional[timedelta] = None): |
| 76 | to_encode = data.copy() |
| 77 | if expires_delta: |
| 78 | expire = datetime.utcnow() + expires_delta |
| 79 | else: |
| 80 | expire = datetime.utcnow() + timedelta(hours=settings.JWT_EXPIRATION_HOURS) |
| 81 | to_encode.update({"exp": expire}) |
| 82 | encoded_jwt = jwt.encode( |
| 83 | to_encode, |
| 84 | settings.JWT_SECRET, |
| 85 | algorithm=settings.JWT_ALGORITHM |
| 86 | ) |
| 87 | return encoded_jwt |
| 88 | |
| 89 | async def get_current_user(token: str = Depends(oauth2_scheme)): |
| 90 | credentials_exception = HTTPException( |