UNPKG

@loopback/docs

Version:
68 lines (49 loc) 1.79 kB
--- lang: en title: 'API docs: authentication.userservice.verifycredentials' keywords: LoopBack 4.0, LoopBack 4 sidebar: lb4_sidebar permalink: /doc/en/lb4/apidocs.authentication.userservice.verifycredentials.html --- <!-- Do not edit this file. It is automatically generated by API Documenter. --> [Home](./index.md) &gt; [@loopback/authentication](./authentication.md) &gt; [UserService](./authentication.userservice.md) &gt; [verifyCredentials](./authentication.userservice.verifycredentials.md) ## UserService.verifyCredentials() method Verify the identity of a user, construct a corresponding user profile using the user information and return the user profile. <b>Signature:</b> ```typescript verifyCredentials(credentials: C): Promise<U>; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | | credentials | <code>C</code> | Credentials for basic auth or configurations for 3rd party. Example see the | <b>Returns:</b> `Promise<U>` ## Example A pseudo code for basic authentication: ```ts verifyCredentials(credentials: C): Promise<U> { // the id field shouldn't be hardcoded user = await UserRepo.find(credentials.id); matched = await passwordService.compare(user.password, credentials.password); if (matched) return user; // throw a JS error, agnostic of the client type throw new Error('authentication failed'); }; ``` A pseudo code for 3rd party authentication: ```ts type UserInfo = { accessToken: string; refreshToken: string; userProfile: string; }; verifyCredentials(credentials: C): Promise<U> { try { userInfo: UserInfo = await getUserInfoFromFB(credentials); } catch (e) { // throw a JS error, agnostic of the client type throw e; } }; ```