Skip to content

Instantly share code, notes, and snippets.

@yskszk63
Created August 24, 2023 16:08
Show Gist options
  • Save yskszk63/e496d0a38729836d44d2507807ee40eb to your computer and use it in GitHub Desktop.
Save yskszk63/e496d0a38729836d44d2507807ee40eb to your computer and use it in GitHub Desktop.
jose
import * as jose from "jose";
const sign = await new jose.SignJWT({ hello: "world!" })
.setProtectedHeader({ alg: "HS256" })
.setIssuedAt()
.setExpirationTime("2h")
.sign(Buffer.from("SECRET!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"));
const { payload } = await jose.jwtVerify(sign, Buffer.from("SECRET!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"));
console.log(payload); // { hello: 'world!', iat: 1692892919, exp: 1692900119 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment