import { SignJWT, jwtVerify } from 'jose';

const secret = new TextEncoder().encode(process.env.NUXT_SESSION_PASSWORD);
async function signJwt(payload, expiresIn = "1m") {
  return new SignJWT(payload).setProtectedHeader({ alg: "HS256" }).setExpirationTime(expiresIn).sign(secret);
}
async function verifyJwtToken(token) {
  const { payload } = await jwtVerify(token, secret);
  return payload;
}

export { signJwt as s, verifyJwtToken as v };
