Skip to content

Instantly share code, notes, and snippets.

@mirsahib
Created November 29, 2020 12:55
Show Gist options
  • Save mirsahib/6e9f0a776b06dfe3c91c176e402483f7 to your computer and use it in GitHub Desktop.
Save mirsahib/6e9f0a776b06dfe3c91c176e402483f7 to your computer and use it in GitHub Desktop.
React_Serverless
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