Skip to content

Commit

Permalink
feat(auth.route.ts-user.route.ts): add role
Browse files Browse the repository at this point in the history
  • Loading branch information
kyzsuukii committed Mar 31, 2024
1 parent 6a441e8 commit 7a375a3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions route/v1/auth.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ router.post(
}
const db = await conn();
const [rows]: any = await db.execute(
"SELECT password, id FROM auth WHERE email = ? LIMIT 1",
"SELECT id, password, role FROM auth WHERE email = ? LIMIT 1",
[email]
);
if (!rows[0]) {
Expand All @@ -86,10 +86,12 @@ router.post(
JSON.stringify(payload),
`${process.env.JWT_SECRET_KEY}`
);
res.json({
msg: "Login success",
token: jwt,
});

if (data.role === "ADMIN") {
res.json({ msg: "Login success", token: jwt, isAdmin: true });
} else {
res.json({ msg: "Login success", token: jwt });
}
} catch (e) {
throw e;
}
Expand Down
4 changes: 2 additions & 2 deletions route/v1/user.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ router.get(
"/me",
passport.authenticate("jwt", { session: false }),
(req: any, res) => {
const { id, email } = req.user;
res.json({ id, email });
const { id, email, role } = req.user;
res.json({ id, email, role });
}
);

Expand Down

0 comments on commit 7a375a3

Please sign in to comment.