Skip to content

Commit

Permalink
fix: post signup hook for ee was using user without platform id
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdulTheActivePiecer authored and abuaboud committed Dec 5, 2023
1 parent 4b118c2 commit 927b8a1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Expand Up @@ -6,6 +6,7 @@ import { otpService } from '../../../otp/otp-service'
import { referralService } from '../../../referrals/referral.service'
import { authenticationHelper } from './authentication-helper'
import { projectService } from '../../../../project/project-service'
import { userService } from '../../../../user/user-service'
import { ProjectType, UserStatus, isNil } from '@activepieces/shared'

export const cloudAuthenticationServiceHooks: AuthenticationServiceHooks = {
Expand All @@ -27,7 +28,8 @@ export const cloudAuthenticationServiceHooks: AuthenticationServiceHooks = {
})
}

const updatedUser = await authenticationHelper.autoVerifyUserIfEligible(user)
await authenticationHelper.autoVerifyUserIfEligible(user)
const updatedUser = await userService.getOneOrFail({ id: user.id })
const { project, token } = await authenticationHelper.getProjectAndTokenOrThrow(user)

if (updatedUser.status !== UserStatus.VERIFIED) {
Expand All @@ -38,7 +40,7 @@ export const cloudAuthenticationServiceHooks: AuthenticationServiceHooks = {
})
}
return {
user: updatedUser,
user: await userService.getOneOrFail({ id: user.id }),
project,
token,
}
Expand Down
Expand Up @@ -22,7 +22,7 @@ export const enterpriseAuthenticationServiceHooks: AuthenticationServiceHooks =
}
}

const project = await projectService.create({
const project = await projectService.create({
displayName: `${user.firstName}'s Project`,
ownerId: user.id,
platformId: undefined,
Expand All @@ -42,8 +42,8 @@ export const enterpriseAuthenticationServiceHooks: AuthenticationServiceHooks =
value: true,
})

const updatedUser = await authenticationHelper.autoVerifyUserIfEligible(user)

await authenticationHelper.autoVerifyUserIfEligible(user)
const updatedUser = await userService.getOneOrFail({ id: user.id })
const { project: updatedProject, token } = await authenticationHelper.getProjectAndTokenOrThrow(user)
return {
user: updatedUser,
Expand Down
3 changes: 3 additions & 0 deletions packages/backend/src/app/user/user-service.ts
Expand Up @@ -33,6 +33,9 @@ export const userService = {
async get({ id }: IdParams): Promise<User | null> {
return userRepo.findOneBy({ id })
},
async getOneOrFail({ id }: IdParams): Promise<User> {
return userRepo.findOneByOrFail({ id })
},

async getMetaInfo({ id }: IdParams): Promise<UserMeta | null> {
const user = await this.get({ id })
Expand Down

0 comments on commit 927b8a1

Please sign in to comment.