Page Contents

Home > @loopback/authentication > UserService > verifyCredentials

UserService.verifyCredentials() method

Verify the identity of a user, construct a corresponding user profile using the user information and return the user profile.


verifyCredentials(credentials: C): Promise<U>;


Parameter Type Description
credentials C Credentials for basic auth or configurations for 3rd party. Example see the




A pseudo code for basic authentication:

verifyCredentials(credentials: C): Promise<U> {
  // the id field shouldn't be hardcoded
  user = await UserRepo.find(;
  matched = await, 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:

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;