Skip to content

Commit

Permalink
fix: admin only
Browse files Browse the repository at this point in the history
  • Loading branch information
potts99 committed Nov 14, 2024
1 parent 5291aec commit 7d5199d
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions apps/api/src/controllers/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,39 @@ export function userRoutes(fastify: FastifyInstance) {
"/api/v1/user/new",

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

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

const hash = await bcrypt.hash(password, 10);
const e = email.toLowerCase();

await prisma.user.create({
data: {
name,
email: e,
password: hash,
isAdmin: admin,
},
});
const hash = await bcrypt.hash(password, 10);

const client = track();
await prisma.user.create({
data: {
name,
email: e,
password: hash,
isAdmin: admin,
},
});

client.capture({
event: "user_created",
distinctId: "uuid",
});
const client = track();

client.shutdownAsync();
client.capture({
event: "user_created",
distinctId: "uuid",
});

reply.send({
success: true,
});
client.shutdownAsync();

reply.send({
success: true,
});
} else {
reply.status(403).send({ message: "Unauthorized", failed: true });
}
}
);

Expand Down

0 comments on commit 7d5199d

Please sign in to comment.