Skip to content

Commit

Permalink
Merge pull request #60 from KOSASIH/deepsource-transform-18574bba
Browse files Browse the repository at this point in the history
style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf
  • Loading branch information
KOSASIH authored May 10, 2024
2 parents 3260aa3 + a24ae6c commit 9e57cd0
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/middleware/auth.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
const jwt = require("jsonwebtoken");
const User = require("../models/user");
const jwt = require('jsonwebtoken')
const User = require('../models/user')

const authenticate = async (req, res, next) => {
const token = req.header("Authorization")?.split(" ")[1];
const token = req.header('Authorization')?.split(' ')[1]

if (!token) {
return res.status(401).json({ message: "Access Denied" });
return res.status(401).json({ message: 'Access Denied' })
}

try {
const decoded = jwt.verify(token, process.env.JWT_SECRET);
req.user = await User.findById(decoded.user_id);
next();
const decoded = jwt.verify(token, process.env.JWT_SECRET)
req.user = await User.findById(decoded.user_id)
next()
} catch (error) {
res.status(400).json({ message: "Invalid Token" });
res.status(400).json({ message: 'Invalid Token' })
}
};
}

module.exports = authenticate;
module.exports = authenticate

0 comments on commit 9e57cd0

Please sign in to comment.