diff --git a/apps/api/src/common/create-user.ts b/apps/api/src/common/create-user.ts index 032d167d..89632822 100644 --- a/apps/api/src/common/create-user.ts +++ b/apps/api/src/common/create-user.ts @@ -7,11 +7,7 @@ import { Logger } from '@nestjs/common' const createUser = async ( dto: Partial & { authProvider: AuthProvider }, prisma: PrismaService -): Promise< - User & { - defaultWorkspace: Workspace - } -> => { +): Promise => { const logger = new Logger('createUser') // Create the user @@ -27,6 +23,11 @@ const createUser = async ( } }) + if (user.isAdmin) { + logger.log(`Created admin user ${user.id}`) + return user + } + // Create the user's default workspace const workspace = await createWorkspace( user, diff --git a/apps/api/src/user/user.e2e.spec.ts b/apps/api/src/user/user.e2e.spec.ts index 2550153c..aef66a6d 100644 --- a/apps/api/src/user/user.e2e.spec.ts +++ b/apps/api/src/user/user.e2e.spec.ts @@ -130,6 +130,26 @@ describe('User Controller Tests', () => { expect(workspace.ownerId).toEqual(createUserResponse.id) }) + it('should skip workspace creation for admin users', async () => { + const createAdminUserResponse = await userService.createUser({ + email: '', + isAdmin: true, + isOnboardingFinished: true, + profilePictureUrl: null + }) + + expect(createAdminUserResponse.defaultWorkspace).toBeUndefined() + + const workspace = await prisma.workspace.findFirst({ + where: { + ownerId: createAdminUserResponse.id, + isDefault: true + } + }) + + expect(workspace).toBeNull() + }) + test('regular user should not be able to access other routes if onboarding is not finished', async () => { // Flip the user's onboarding status to false await prisma.user.update({