Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
sachin
commited on
Commit
·
c0849df
1
Parent(s):
78be025
disble-logs for api
Browse files- src/server/utils/auth.py +7 -7
src/server/utils/auth.py
CHANGED
@@ -49,7 +49,7 @@ class Settings(BaseSettings):
|
|
49 |
env_file_encoding = "utf-8"
|
50 |
|
51 |
settings = Settings()
|
52 |
-
logger.info(f"Loaded API_KEY_SECRET at startup: {settings.api_key_secret}")
|
53 |
|
54 |
# Seed initial data (optional)
|
55 |
def seed_initial_data():
|
@@ -93,9 +93,9 @@ class RegisterRequest(BaseModel):
|
|
93 |
async def create_access_token(user_id: str) -> str:
|
94 |
expire = datetime.utcnow() + timedelta(minutes=settings.token_expiration_minutes)
|
95 |
payload = {"sub": user_id, "exp": expire.timestamp()}
|
96 |
-
logger.info(f"Signing token with API_KEY_SECRET: {settings.api_key_secret}")
|
97 |
token = jwt.encode(payload, settings.api_key_secret, algorithm="HS256")
|
98 |
-
logger.info(f"Generated access token for user: {user_id}")
|
99 |
return token
|
100 |
|
101 |
async def get_current_user(credentials: HTTPAuthorizationCredentials = Depends(bearer_scheme)) -> str:
|
@@ -106,10 +106,10 @@ async def get_current_user(credentials: HTTPAuthorizationCredentials = Depends(b
|
|
106 |
headers={"WWW-Authenticate": "Bearer"},
|
107 |
)
|
108 |
try:
|
109 |
-
logger.info(f"Received token: {token}")
|
110 |
-
logger.info(f"Verifying token with API_KEY_SECRET: {settings.api_key_secret}")
|
111 |
payload = jwt.decode(token, settings.api_key_secret, algorithms=["HS256"], options={"verify_exp": False})
|
112 |
-
logger.info(f"Decoded payload: {payload}")
|
113 |
token_data = TokenPayload(**payload)
|
114 |
user_id = token_data.sub
|
115 |
|
@@ -123,7 +123,7 @@ async def get_current_user(credentials: HTTPAuthorizationCredentials = Depends(b
|
|
123 |
current_time = datetime.utcnow().timestamp()
|
124 |
logger.info(f"Current time: {current_time}, Token exp: {token_data.exp}")
|
125 |
if current_time > token_data.exp:
|
126 |
-
logger.warning(f"Token expired: current_time={current_time}, exp={token_data.exp}")
|
127 |
raise HTTPException(
|
128 |
status_code=status.HTTP_401_UNAUTHORIZED,
|
129 |
detail="Token has expired",
|
|
|
49 |
env_file_encoding = "utf-8"
|
50 |
|
51 |
settings = Settings()
|
52 |
+
#logger.info(f"Loaded API_KEY_SECRET at startup: {settings.api_key_secret}")
|
53 |
|
54 |
# Seed initial data (optional)
|
55 |
def seed_initial_data():
|
|
|
93 |
async def create_access_token(user_id: str) -> str:
|
94 |
expire = datetime.utcnow() + timedelta(minutes=settings.token_expiration_minutes)
|
95 |
payload = {"sub": user_id, "exp": expire.timestamp()}
|
96 |
+
#logger.info(f"Signing token with API_KEY_SECRET: {settings.api_key_secret}")
|
97 |
token = jwt.encode(payload, settings.api_key_secret, algorithm="HS256")
|
98 |
+
#logger.info(f"Generated access token for user: {user_id}")
|
99 |
return token
|
100 |
|
101 |
async def get_current_user(credentials: HTTPAuthorizationCredentials = Depends(bearer_scheme)) -> str:
|
|
|
106 |
headers={"WWW-Authenticate": "Bearer"},
|
107 |
)
|
108 |
try:
|
109 |
+
#logger.info(f"Received token: {token}")
|
110 |
+
#logger.info(f"Verifying token with API_KEY_SECRET: {settings.api_key_secret}")
|
111 |
payload = jwt.decode(token, settings.api_key_secret, algorithms=["HS256"], options={"verify_exp": False})
|
112 |
+
#logger.info(f"Decoded payload: {payload}")
|
113 |
token_data = TokenPayload(**payload)
|
114 |
user_id = token_data.sub
|
115 |
|
|
|
123 |
current_time = datetime.utcnow().timestamp()
|
124 |
logger.info(f"Current time: {current_time}, Token exp: {token_data.exp}")
|
125 |
if current_time > token_data.exp:
|
126 |
+
#logger.warning(f"Token expired: current_time={current_time}, exp={token_data.exp}")
|
127 |
raise HTTPException(
|
128 |
status_code=status.HTTP_401_UNAUTHORIZED,
|
129 |
detail="Token has expired",
|