diff --git a/code/backend/nest_backend/routes/users/login.py b/code/backend/nest_backend/routes/users/login.py index d8e6638..e26c227 100644 --- a/code/backend/nest_backend/routes/users/login.py +++ b/code/backend/nest_backend/routes/users/login.py @@ -3,6 +3,7 @@ from ...database import * from ...gestione import * from flask_jwt_extended import create_access_token from flask_cors import cross_origin +from datetime import timedelta, datetime @cross_origin() @@ -18,7 +19,12 @@ def page_login(): email = request.json.get("email", None) password = request.json.get("password", None) if authenticate(email, password): - access_token = create_access_token(identity=email) + # Find today's date + now = datetime.now() + # Add 30 days to it; that's your token expiration date + delta = timedelta(days=30) + expiration = now + delta + access_token = create_access_token(identity=email, expires_delta=delta) user = find_user(email) - return json_success({"access_token": access_token, 'user': user.to_json()}), 201 + return json_success({"access_token": access_token, 'user': user.to_json(), "expiration": expiration}), 201 return json_error("Bad username or password."), 401