Update app.py
Browse files
app.py
CHANGED
@@ -319,10 +319,15 @@ def create_access_token(data: dict, expires_delta: timedelta = timedelta(minutes
|
|
319 |
def verify_token(token: str = Depends(oauth2_scheme)):
|
320 |
try:
|
321 |
payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
|
322 |
-
|
|
|
|
|
|
|
323 |
except jwt.ExpiredSignatureError:
|
324 |
-
raise HTTPException(status_code=
|
325 |
-
|
|
|
|
|
326 |
def validate_token(token: str):
|
327 |
try:
|
328 |
payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
|
|
|
319 |
def verify_token(token: str = Depends(oauth2_scheme)):
|
320 |
try:
|
321 |
payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
|
322 |
+
user_email = payload.get("sub")
|
323 |
+
if user_email is None:
|
324 |
+
raise HTTPException(status_code=401, detail="Invalid authentication credentials")
|
325 |
+
return user_email
|
326 |
except jwt.ExpiredSignatureError:
|
327 |
+
raise HTTPException(status_code=401, detail="Token has expired")
|
328 |
+
except jwt.PyJWTError:
|
329 |
+
raise HTTPException(status_code=401, detail="Could not validate credentials")
|
330 |
+
|
331 |
def validate_token(token: str):
|
332 |
try:
|
333 |
payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
|