Skip to content

Commit a215419

Browse files
author
Lasim
committed
feat: streamline user registration by removing manual session creation and simplifying response handling
1 parent 16edafa commit a215419

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

services/backend/src/routes/auth/registerEmail.ts

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import type { FastifyInstance, FastifyReply } from 'fastify';
3-
import { getLucia } from '../../lib/lucia';
3+
44
import { type RegisterEmailInput } from './schemas';
55
import { getDb, getSchema } from '../../db';
66
import { eq, or } from 'drizzle-orm';
@@ -69,7 +69,7 @@ export default async function registerEmailRoute(fastify: FastifyInstance) {
6969
role_id: defaultRole, // Assign role (no default in schema, so we must provide it)
7070
});
7171

72-
// Verify user was created successfully before creating session
72+
// Verify user was created successfully
7373
const createdUser = await (db as any)
7474
.select()
7575
.from(authUserTable)
@@ -92,25 +92,9 @@ export default async function registerEmailRoute(fastify: FastifyInstance) {
9292
// Don't fail registration if team creation fails, just log the error
9393
}
9494

95-
// Create session manually (Lucia's createSession has issues with our schema)
96-
const sessionId = generateId(40); // Generate session ID
97-
const expiresAt = Date.now() + 1000 * 60 * 60 * 24 * 30; // 30 days
98-
99-
const authSessionTable = schema.authSession;
100-
101-
// Insert session directly into database
102-
await (db as any).insert(authSessionTable).values({
103-
id: sessionId,
104-
user_id: userId,
105-
expires_at: expiresAt
95+
return reply.status(201).send({
96+
message: 'User registered successfully. Please log in to continue.'
10697
});
107-
108-
fastify.log.info(`Session created successfully for user: ${userId}`);
109-
110-
const sessionCookie = getLucia().createSessionCookie(sessionId);
111-
112-
reply.setCookie(sessionCookie.name, sessionCookie.value, sessionCookie.attributes);
113-
return reply.status(201).send({ message: 'User registered successfully.' });
11498

11599
} catch (error) {
116100
fastify.log.error(error, 'Error during email registration:');

0 commit comments

Comments
 (0)