update
This commit is contained in:
@@ -54,11 +54,20 @@ function generateAuthToken(user) {
|
||||
restaurants: user.restaurants,
|
||||
},
|
||||
jwtSecret,
|
||||
{ expiresIn: "1h" }
|
||||
{ expiresIn: "15m" }
|
||||
);
|
||||
return token;
|
||||
}
|
||||
|
||||
function generateRefreshToken(userId) {
|
||||
const token = jwt.sign({
|
||||
id: userId
|
||||
}, jwtSecret, {
|
||||
expiresIn: "1h"
|
||||
});
|
||||
return token;
|
||||
}
|
||||
|
||||
function generatePasswordResetToken(email) {
|
||||
const token = jwt.sign(
|
||||
{
|
||||
@@ -98,6 +107,17 @@ function validateUserToken(token) {
|
||||
}
|
||||
}
|
||||
|
||||
function validateRefreshToken(token) {
|
||||
if (!token) throw newError("Brak dostępu", 401);
|
||||
try {
|
||||
const verified = jwt.verify(token, jwtSecret, { ignoreExpiration: false });
|
||||
if (!verified) throw newError("Brak dostępu", 401);
|
||||
return verified;
|
||||
} catch (error) {
|
||||
throw newError("Brak dostępu", 401);
|
||||
}
|
||||
}
|
||||
|
||||
async function validateDishId(id) {
|
||||
if (!mongoose.Types.ObjectId.isValid(id)) {
|
||||
throw newError("Niewłaściwy ID", 400);
|
||||
@@ -174,3 +194,5 @@ exports.verifyRestaurantAccess = verifyRestaurantAccess;
|
||||
exports.yearFromNowDate = yearFromNowDate;
|
||||
exports.hashPass = hashPass;
|
||||
exports.saveImage = saveImage;
|
||||
exports.generateRefreshToken = generateRefreshToken;
|
||||
exports.validateRefreshToken = validateRefreshToken;
|
||||
|
||||
Reference in New Issue
Block a user