Created
March 30, 2024 18:14
-
-
Save Kernix13/d28d08cf2e4fe23afcec00614fcfbb9d to your computer and use it in GitHub Desktop.
Set server cookie
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// npm install cookie | |
const cookie = require('cookie'); | |
const handler = async (event) => { | |
const body = JSON.parse(event.body); | |
// pick a generic username and password for now | |
if (body.username == "some_name" && body.password == "some_password") { | |
const myCookie = cookie.serialize("petadoption", "apsodifugyhtjrkelwqzmxncbv0918273645", { | |
httpOnly: true, | |
path: '/', | |
sameSite: 'strict', | |
maxAge: 60 * 60 * 24 // set for 24 hours | |
}) | |
return { | |
statusCode: 200, | |
headers: { | |
'Content-Type': 'application/json', | |
'Set-Cookie': myCookie, | |
'Location': '/' | |
}, | |
body: JSON.stringify({ success: true }) | |
}; | |
} | |
return { | |
statusCode: 200, | |
headers: {'Content-Type': 'application/json'}, | |
body: JSON.stringify({ success: false }) | |
}; | |
}; | |
module.exports = { handler }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment