Created
November 29, 2020 12:55
-
-
Save mirsahib/6e9f0a776b06dfe3c91c176e402483f7 to your computer and use it in GitHub Desktop.
React_Serverless
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
import jwt from "jsonwebtoken"; | |
import cookie from "cookie"; | |
function createJwtCookie(userId, email) { | |
const token = jwt.sign({ userId, email }, process.env.REACT_APP_JWT_TOKEN, { | |
expiresIn: "10 days", | |
}); | |
const jwtCookie = cookie.serialize("jwt", token, { | |
secure: process.env.NETLIFY_DEV !== "true", | |
httpOnly: true, | |
path: "/", | |
}); | |
return jwtCookie; | |
} | |
function clearCookie() { | |
return "jwt=deleted; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT"; | |
} | |
export { createJwtCookie, clearCookie }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment