@loopback/docs
Version:
Documentation files rendered at [https://loopback.io](https://loopback.io)
67 lines (50 loc) • 1.9 kB
Markdown
lang: en
title: 'API docs: authentication.userservice.verifycredentials'
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.userservice.verifycredentials.html
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [@loopback/authentication](./authentication.md) > [UserService](./authentication.userservice.md) > [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 | C | 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;
}
};
```