MCPcopy Create free account
hub / github.com/FlowiseAI/Flowise / verifyAndLogin

Function verifyAndLogin

packages/server/src/enterprise/sso/SSOBase.ts:38–148  ·  view source on GitHub ↗
(
        app: express.Application,
        email: string,
        done: (err?: Error | null, user?: Express.User, info?: any) => void,
        profile: passport.Profile,
        accessToken: string | object,
        refreshToken: string
    )

Source from the content-addressed store, hash-verified

36 abstract initialize(): void
37 abstract refreshToken(ssoRefreshToken: string): Promise<{ [key: string]: any }>
38 async verifyAndLogin(
39 app: express.Application,
40 email: string,
41 done: (err?: Error | null, user?: Express.User, info?: any) => void,
42 profile: passport.Profile,
43 accessToken: string | object,
44 refreshToken: string
45 ) {
46 let queryRunner
47 const ssoProviderName = this.getProviderName()
48 try {
49 queryRunner = getRunningExpressApp().AppDataSource.createQueryRunner()
50 await queryRunner.connect()
51
52 const userService = new UserService()
53 const organizationService = new OrganizationService()
54 const workspaceUserService = new WorkspaceUserService()
55
56 let user: any = await userService.readUserByEmail(email, queryRunner)
57 let wu: any = {}
58
59 if (!user) {
60 // In ENTERPRISE mode, we don't want to create a new user if the user is not found
61 if (getRunningExpressApp().identityManager.getPlatformType() === Platform.ENTERPRISE) {
62 throw new InternalFlowiseError(StatusCodes.NOT_FOUND, UserErrorMessage.USER_NOT_FOUND)
63 }
64 // no user found, register the user
65 const data: any = {
66 user: {
67 email: email,
68 name: profile.displayName || email,
69 status: UserStatus.ACTIVE,
70 credential: undefined
71 }
72 }
73 if (getRunningExpressApp().identityManager.getPlatformType() === Platform.CLOUD) {
74 const accountService = new AccountService()
75 const newAccount = await accountService.register(data)
76 wu = newAccount.workspaceUser
77 wu.workspace = newAccount.workspace
78 user = newAccount.user
79 }
80 } else {
81 if (user.status === UserStatus.INVITED) {
82 const data: any = {
83 user: {
84 ...user,
85 email,
86 name: profile.displayName || '',
87 status: UserStatus.ACTIVE,
88 credential: undefined
89 }
90 }
91 const accountService = new AccountService()
92 const newAccount = await accountService.register(data)
93 user = newAccount.user
94 }
95 let wsUserOrUsers = await workspaceUserService.readWorkspaceUserByLastLogin(user?.id, queryRunner)

Callers

nothing calls this directly

Calls 13

readUserByEmailMethod · 0.95
registerMethod · 0.95
readGeneralRoleByNameMethod · 0.95
readRoleByIdMethod · 0.95
readOrganizationByIdMethod · 0.95
getRunningExpressAppFunction · 0.90
parseMethod · 0.65
getProviderNameMethod · 0.45
connectMethod · 0.45
getFeaturesByPlanMethod · 0.45

Tested by

no test coverage detected