For Frontend practice
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user