Page Contents

Home > @loopback/authentication > UserIdentityService > findOrCreateUser

UserIdentityService.findOrCreateUser() method

find or create a local user using a profile from an external source

Signature:

findOrCreateUser(userIdentity: I): Promise<U>;

Parameters

Parameter Type Description
userIdentity I  

Returns:

Promise<U>

Example

async findOrCreateUser( ldapUser: LDAPUserIdentity, ): Promise { let user: UserProfile = await this.userRepository.findOrCreate({ name: ldapUser.cn, username: ldapUser.mail, roles: \_.map(ldapUser.memberof\['ou=roles,dc=mydomain,o=myOrg'\], 'cn') }); await this.linkExternalProfile(user.id, ldapUser); return user; }