37 lines
690 B
JavaScript
37 lines
690 B
JavaScript
const jwt = require("jsonwebtoken");
|
|
const env = require("../../config/env");
|
|
|
|
class AuthService {
|
|
constructor() {
|
|
this.cookieName = env.cookieName;
|
|
}
|
|
|
|
signToken(payload) {
|
|
return jwt.sign(payload, env.jwtSecret, { expiresIn: env.jwtExpiresIn });
|
|
}
|
|
|
|
verifyToken(token) {
|
|
return jwt.verify(token, env.jwtSecret);
|
|
}
|
|
|
|
cookieOptions() {
|
|
return {
|
|
httpOnly: true,
|
|
sameSite: "lax",
|
|
secure: env.cookieSecure,
|
|
path: "/",
|
|
maxAge: 7 * 24 * 60 * 60 * 1000
|
|
};
|
|
}
|
|
|
|
clearCookieOptions() {
|
|
return {
|
|
httpOnly: true,
|
|
sameSite: "lax",
|
|
secure: env.cookieSecure,
|
|
path: "/"
|
|
};
|
|
}
|
|
}
|
|
|
|
module.exports = AuthService; |