Skip to content

Commit

Permalink
fixed bugs in auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Basheer3648734 committed Jun 1, 2020
1 parent 2514f42 commit 95aa138
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/controllers/adminController.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ exports.AdminLogin = async (req, res) => {
*/
exports.AdminSignout = async (req, res) => {
try {
console.log(req.user._id);
const user = await AdminModel.findById(req.user._id);
console.log(user);
user.tokens = [];
Expand All @@ -113,7 +114,8 @@ exports.AdminUpdate = async (req, res) => {
try {
const user = await AdminModel.findByIdAndUpdate(
{ _id: req.user._id },
req.body
req.body,
{ new: true, runValidators: true }
);
const updatedUser = await user.save();
res.status(200).send({
Expand Down
6 changes: 3 additions & 3 deletions src/middleware/checkAuthToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ module.exports = async (req, res, next) => {
const token = req.headers.authorization.split(' ')[1];

const { user } = await verify(token, process.env.JWT_SECRET);
console.log(user);
const userExist = await adminModel.findOne({ email: user.email });

const userExist = await adminModel.findOne({ _id: user._id });
if (!userExist) {
throw new Error('invalid Token');
}
Expand All @@ -19,7 +19,7 @@ module.exports = async (req, res, next) => {
}

req.user = userExist;
console.log(req.user);

next();
} catch (err) {
res.status(401).json({
Expand Down

0 comments on commit 95aa138

Please sign in to comment.