Skip to content

Commit

Permalink
feat(core-auth0-actions): Add logs
Browse files Browse the repository at this point in the history
  • Loading branch information
alllenshibu committed Feb 29, 2024
1 parent c216991 commit 70e6630
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions apps/core-auth0-actions/src/controllers/newuser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export const addNewUserToDatabaseOnRegister = async (req: Request, res: Response
return res.status(500).send('Error creating user');
}

console.log(`User ${userId} with email ${email} created`);

return res.status(200).send(newUser);
} catch (err) {
console.error(err);
Expand Down
12 changes: 9 additions & 3 deletions apps/core-auth0-actions/src/middlewares/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,23 @@ export const authorize = (req: Request, res: Response, next: NextFunction) => {
const { authorization } = req.headers;

if (!authorization) {
return res.status(401).send('Unauthorized');
return res.status(403).json({
message: 'No authorization header provided',
});
}

const token = authorization.split(' ')[1];

if (!token) {
return res.status(401).send('Unauthorized');
return res.status(403).json({
message: 'No token provided',
});
}

if (token !== process.env.AUTHORIZATION_SECRET) {
return res.status(401).send('Unauthorized');
return res.status(401).json({
message: 'Unauthorized',
});
}

next();
Expand Down

0 comments on commit 70e6630

Please sign in to comment.