Add role field to invites, apply role on acceptance
This commit is contained in:
@@ -61,6 +61,7 @@ export const invites = pgTable('invites', {
|
||||
id: uuid('id').primaryKey().defaultRandom(),
|
||||
email: text('email').notNull(),
|
||||
name: text('name').notNull(),
|
||||
role: text('role').default('user'), // Role to assign on acceptance: admin, user
|
||||
token: text('token').notNull().unique(),
|
||||
invitedBy: text('invited_by').references(() => users.id, { onDelete: 'set null' }),
|
||||
status: inviteStatusEnum('status').default('pending').notNull(),
|
||||
|
||||
@@ -115,6 +115,7 @@ export const adminRoutes = new Elysia({ prefix: '/admin' })
|
||||
const [invite] = await db.insert(invites).values({
|
||||
email: body.email,
|
||||
name: body.name,
|
||||
role: body.role || 'user',
|
||||
token,
|
||||
invitedBy: (user as User).id,
|
||||
expiresAt,
|
||||
@@ -149,6 +150,7 @@ export const adminRoutes = new Elysia({ prefix: '/admin' })
|
||||
body: t.Object({
|
||||
email: t.String({ format: 'email' }),
|
||||
name: t.String({ minLength: 1 }),
|
||||
role: t.Optional(t.Union([t.Literal('admin'), t.Literal('user')])),
|
||||
}),
|
||||
})
|
||||
|
||||
|
||||
@@ -75,6 +75,11 @@ export const authRoutes = new Elysia({ prefix: '/auth' })
|
||||
});
|
||||
|
||||
if (newUser) {
|
||||
// Set role from invite if specified
|
||||
if (invite.role && invite.role !== 'user') {
|
||||
await db.update(users).set({ role: invite.role }).where(eq(users.id, newUser.id));
|
||||
}
|
||||
|
||||
// Create default inbox project
|
||||
await db.insert(projects).values({
|
||||
userId: newUser.id,
|
||||
|
||||
Reference in New Issue
Block a user