12345678910111213141516 |
- import os
- from jose import JWTError, jwt
- from datetime import datetime, timedelta
- # Generate token function
- def create_access_token(data: dict, expires_delta: timedelta = None):
- to_encode = data.copy()
- if expires_delta:
- expire = datetime.now() + expires_delta
- else:
- expire = datetime.now() + timedelta(minutes=15)
- to_encode.update({"exp": expire})
- encoded_jwt = jwt.encode(to_encode, os.environ["SECRET_KEY"], algorithm="HS256")
- return encoded_jwt
|