UNPKG

@authxyz/core

Version:

Authxyz core package for authentication implementations and providers.

19 lines (18 loc) 772 B
import jwt from "jsonwebtoken"; import moment from "moment"; export const cookieName = "_auth_kqda"; function signJwtAuth({ data, options, secret }) { return jwt.sign(data, secret, options); } function signCookieAuth(res, { data, options }) { res.cookie(cookieName, data, Object.assign({ httpOnly: true, secure: true, sameSite: "none", signed: true, expires: moment().add(7, "days").toDate() }, (options && Object.assign({}, options)))); } function signAuth({ method = "JWT", res, data, secret, options }) { if (method === "JWT") { return signJwtAuth({ data, options: options.jwtOptions, secret }); } else { return signCookieAuth(res, { data, options: options.cookieOptions }); } } export { signCookieAuth, signJwtAuth, signAuth };