CognxSafeTrack commited on
Commit
c54affa
·
1 Parent(s): b75a181

fix: replace Zod schema with JSON Schema in auth/login to resolve Fastify v5 startup crash

Browse files
Files changed (1) hide show
  1. apps/api/src/routes/auth.ts +9 -8
apps/api/src/routes/auth.ts CHANGED
@@ -8,18 +8,20 @@ export async function authRoutes(fastify: FastifyInstance) {
8
  // Login with Email/Password
9
  fastify.post('/login', {
10
  schema: {
11
- body: z.object({
12
- email: z.string().email(),
13
- password: z.string(),
14
- organizationId: z.string().optional() // Optional for super admins, required for others
15
- })
 
 
 
 
16
  }
17
  }, async (request, reply) => {
18
  const { email, password, organizationId } = request.body as any;
19
  logger.info(`[AUTH] Login attempt for ${email} (Org: ${organizationId || 'default'})`);
20
 
21
- // If no organizationId provided, we check for Super Admin in 'default-org-id'
22
- // or we need to ask for it.
23
  const orgId = organizationId || 'default-org-id';
24
 
25
  const user = await AuthService.findUserByEmail(email, orgId);
@@ -34,7 +36,6 @@ export async function authRoutes(fastify: FastifyInstance) {
34
  return reply.code(401).send({ error: 'Unauthorized', message: 'Invalid email or password' });
35
  }
36
 
37
- // Generate JWT
38
  const token = fastify.jwt.sign({
39
  id: user.id,
40
  organizationId: user.organizationId,
 
8
  // Login with Email/Password
9
  fastify.post('/login', {
10
  schema: {
11
+ body: {
12
+ type: 'object',
13
+ required: ['email', 'password'],
14
+ properties: {
15
+ email: { type: 'string', format: 'email' },
16
+ password: { type: 'string' },
17
+ organizationId: { type: 'string' }
18
+ }
19
+ }
20
  }
21
  }, async (request, reply) => {
22
  const { email, password, organizationId } = request.body as any;
23
  logger.info(`[AUTH] Login attempt for ${email} (Org: ${organizationId || 'default'})`);
24
 
 
 
25
  const orgId = organizationId || 'default-org-id';
26
 
27
  const user = await AuthService.findUserByEmail(email, orgId);
 
36
  return reply.code(401).send({ error: 'Unauthorized', message: 'Invalid email or password' });
37
  }
38
 
 
39
  const token = fastify.jwt.sign({
40
  id: user.id,
41
  organizationId: user.organizationId,