mirror of
https://github.com/pawelmalak/flame.git
synced 2026-02-28 09:23:12 +08:00
Added auth middleware. Added access control to apps
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
module.exports = {
|
||||
login: require('./login'),
|
||||
validate: require('./validate'),
|
||||
};
|
||||
|
||||
21
controllers/auth/validate.js
Normal file
21
controllers/auth/validate.js
Normal file
@@ -0,0 +1,21 @@
|
||||
const asyncWrapper = require('../../middleware/asyncWrapper');
|
||||
const ErrorResponse = require('../../utils/ErrorResponse');
|
||||
const jwt = require('jsonwebtoken');
|
||||
|
||||
// @desc Verify token
|
||||
// @route POST /api/auth/verify
|
||||
// @access Public
|
||||
const validate = asyncWrapper(async (req, res, next) => {
|
||||
try {
|
||||
jwt.verify(req.body.token, process.env.SECRET);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: { token: { isValid: true } },
|
||||
});
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Token expired', 401));
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = validate;
|
||||
Reference in New Issue
Block a user