@loopback/docs
Version:
Documentation files rendered at [https://loopback.io](https://loopback.io)
67 lines (35 loc) • 1.55 kB
Markdown
---
lang: en
title: 'API docs: authentication.useridentityservice.findorcreateuser'
keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI
sidebar: lb4_sidebar
editurl: https://github.com/loopbackio/loopback-next/tree/master/packages/authentication
permalink: /doc/en/lb4/apidocs.authentication.useridentityservice.findorcreateuser.html
---
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [@loopback/authentication](./authentication.md) > [UserIdentityService](./authentication.useridentityservice.md) > [findOrCreateUser](./authentication.useridentityservice.findorcreateuser.md)
## UserIdentityService.findOrCreateUser() method
find or create a local user using a profile from an external source
**Signature:**
```typescript
findOrCreateUser(userIdentity: I): Promise<U>;
```
## Parameters
<table><thead><tr><th>
Parameter
</th><th>
Type
</th><th>
Description
</th></tr></thead>
<tbody><tr><td markdown="1">
userIdentity
</td><td markdown="1">
I
</td><td markdown="1">
</td></tr>
</tbody></table>
**Returns:**
Promise<U>
## Example
async findOrCreateUser( ldapUser: LDAPUserIdentity, ): Promise<UserProfile> { 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; }