Skip to content

Commit 7d5199d

Browse files
committed
fix: admin only
1 parent 5291aec commit 7d5199d

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

apps/api/src/controllers/users.ts

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,33 +38,39 @@ export function userRoutes(fastify: FastifyInstance) {
3838
"/api/v1/user/new",
3939

4040
async (request: FastifyRequest, reply: FastifyReply) => {
41-
const { email, password, name, admin }: any = request.body;
41+
const session = await checkSession(request);
4242

43-
const e = email.toLowerCase();
43+
if (session!.isAdmin) {
44+
const { email, password, name, admin }: any = request.body;
4445

45-
const hash = await bcrypt.hash(password, 10);
46+
const e = email.toLowerCase();
4647

47-
await prisma.user.create({
48-
data: {
49-
name,
50-
email: e,
51-
password: hash,
52-
isAdmin: admin,
53-
},
54-
});
48+
const hash = await bcrypt.hash(password, 10);
5549

56-
const client = track();
50+
await prisma.user.create({
51+
data: {
52+
name,
53+
email: e,
54+
password: hash,
55+
isAdmin: admin,
56+
},
57+
});
5758

58-
client.capture({
59-
event: "user_created",
60-
distinctId: "uuid",
61-
});
59+
const client = track();
6260

63-
client.shutdownAsync();
61+
client.capture({
62+
event: "user_created",
63+
distinctId: "uuid",
64+
});
6465

65-
reply.send({
66-
success: true,
67-
});
66+
client.shutdownAsync();
67+
68+
reply.send({
69+
success: true,
70+
});
71+
} else {
72+
reply.status(403).send({ message: "Unauthorized", failed: true });
73+
}
6874
}
6975
);
7076

0 commit comments

Comments
 (0)