File tree Expand file tree Collapse file tree 1 file changed +26
-20
lines changed
Expand file tree Collapse file tree 1 file changed +26
-20
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments