title: Loopback 4 authentication error while binding custom service
body: <p>I have followed this <a href="https://github.com/strongloop/loopback-next/tree/master/extensions/authentication-jwt#customizing-user" rel="nofollow noreferrer">link</a> for creating custom service for authentication in loopback 4. I successfully created the service but while binding this service in application.ts I am getting the following error.</p>
  
  <blockquote>
    <p>Argument of type 'typeof CustomUserService' is not assignable to
    parameter of type 'Constructor>'.<br>
    Construct signature return types 'CustomUserService' and
    'UserService' are incompatible.
        The types returned by 'verifyCredentials(...)' are incompatible between these types.
          Type 'Promise'
    is not assignable to type
    'Promise'.
            Property 'userCredentials' is missing in type 'import("d:/ionic-pr/loopback-projects/custom/src/models/user.model").User'
    but required in type
    'import("d:/ionic-pr/loopback-projects/custom/node_modules/@loopback/authentication-jwt/dist/models/user.model").User'</p>
  </blockquote>
  
  <p><strong>GIT REPOSITORY</strong> - <a href="https://github.com/pratikjaiswal15/loopbck4uth" rel="nofollow noreferrer">https://github.com/pratikjaiswal15/loopbck4uth</a></p>
  
  <p>I have two models user and userCred with has one realtionship.  The relation name is <code>userCred</code>.</p>
  
  <p>here is the code </p>
  
  <p>thank you in advance </p>
  
  <p>application.ts</p>
  
  <pre><code>import {UserCredRepository, UserRepository} from './repositories';
  import {CustomUserService} from './services/custom-user.service';
  import {UserServiceBindings} from '@loopback/authentication-jwt';
  
  // Bind user service inside constructor
      this.bind(UserServiceBindings.USER_SERVICE).toClass(CustomUserService),// error on this line
  
        // Bind user and credentials repository
        this.bind(UserServiceBindings.USER_REPOSITORY).toClass(
          UserRepository,
        ),
  
        this.bind(UserServiceBindings.USER_CREDENTIALS_REPOSITORY).toClass(
          UserCredRepository,
        )
  </code></pre>
  
  <p>custom-service.ts</p>
  
  <pre><code>import {UserService} from '@loopback/authentication';
  import {repository} from '@loopback/repository';
  import {HttpErrors} from '@loopback/rest';
  import {securityId, UserProfile} from '@loopback/security';
  import {compare} from 'bcryptjs';
  // User --&gt; MyUser
  import {User} from '../models/user.model';
  // UserRepository --&gt; MyUserRepository
  import {Credentials, UserRepository} from '../repositories/user.repository';
  
  
  export class CustomUserService implements UserService&lt;User, Credentials&gt; {
    constructor(
      // UserRepository --&gt; MyUserRepository
      @repository(UserRepository) public userRepository: UserRepository,
    ) {}
  
    // User --&gt; MyUser
    async verifyCredentials(credentials: Credentials): Promise&lt;User&gt; {
      const invalidCredentialsError = 'Invalid email or password.';
  
      const foundUser = await this.userRepository.findOne({
        where: {email: credentials.email},
      });
      if (!foundUser) {
        throw new HttpErrors.Unauthorized(invalidCredentialsError);
      }
  
      const credentialsFound = await this.userRepository.findCredentials(
        foundUser.id,
      );
      if (!credentialsFound) {
        throw new HttpErrors.Unauthorized(invalidCredentialsError);
      }
  
      const passwordMatched = await compare(
        credentials.password,
        credentialsFound.password,
      );
  
      if (!passwordMatched) {
        throw new HttpErrors.Unauthorized(invalidCredentialsError);
      }
  
      return foundUser;
    }
  
    // User --&gt; MyUser
    convertToUserProfile(user: User): UserProfile {
  
      let address = ''
      if (user.address) {
        address = user.address
      }
  
      return {
        [securityId]: user.id!.toString(),
        name: user.name,
        id: user.id,
        email: user.email,
        address: address
  
      };
  
  
    }
  }
  </code></pre>
  
  <p>user.repositor.ts</p>
  
  <pre><code>import {Getter, inject} from '@loopback/core';
  import {DefaultCrudRepository, HasOneRepositoryFactory, repository} from '@loopback/repository';
  import {MygodDataSource} from '../datasources';
  import {User, UserCred, UserRelations} from '../models';
  import {UserCredRepository} from './user-cred.repository';
  
  export type Credentials = {
    email: string;
    password: string;
  };
  
  
  
  export class UserRepository extends DefaultCrudRepository&lt;
    User,
    typeof User.prototype.id,
    UserRelations
    &gt; {
  
    public readonly userCred: HasOneRepositoryFactory&lt;UserCred, typeof User.prototype.id&gt;;
  
    constructor(
      @inject('datasources.mygod') dataSource: MygodDataSource, @repository.getter('UserCredRepository') protected userCredRepositoryGetter: Getter&lt;UserCredRepository&gt;,
    ) {
      super(User, dataSource);
      this.userCred = this.createHasOneRepositoryFactoryFor('userCred', userCredRepositoryGetter);
      this.registerInclusionResolver('userCred', this.userCred.inclusionResolver);
    }
  
  
    async findCredentials(
      userId: typeof User.prototype.id,
    ): Promise&lt;UserCred | undefined&gt; {
      try {
        return await this.userCred(userId).get();
      } catch (err) {
        if (err.code === 'ENTITY_NOT_FOUND') {
          return undefined;
        }
        throw err;
      }
    }
  }
  </code></pre>