1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-25 06:24:19 +00:00

🔧 Increase token expiration date to 30 days, and send it in the login response

This commit is contained in:
Stefano Pigozzi 2021-04-29 03:53:20 +02:00
parent 2b488d9028
commit a481a4e087
Signed by untrusted user who does not match committer: steffo
GPG key ID: 6965406171929D01

View file

@ -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