I am trying to figure out how to handle the login to a web app I am building using aws technology. I've created a lambda function in python that checks if the username and the password sent using javascript fetch
function match with a row in a DynamoDb table. If there is a match I want to send a session ID which I store on another table.
In the lambda function I create a cookie string that I send as a json object in this way:
if password == item['Password']:
login_ok = True
else:
login_ok = False
my_response = {
"str": str(login_ok)
}
# return a properly formatted JSON object
return {
'statusCode': 200,
'headers': { 'Set-Cookie': 'sessionId=38afes7a8' },
'body': json.dumps(my_response),
}
What should I do now on the client web page to create the cookie? I tried to follow the step #2 of this guide but I can't see the cookie. Is this the simplest way to achieve my goal?
Thanks, Stenio
Edit1: change code to use headers as suggested in the comments.
I would strongly advise against building this yourself. The best way on AWS is to use Amazon Cognito , a simple and secure service that lets you add user sign-up, sign-in, and access control to your web and mobile apps quickly and easily.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.