I am trying to use my custom MyUserService
which implement UserService<MyUser, MyCredentials>
:
export class MyUserService implements UserService<Account, LoginCredential> { ... }
The difference from loopback's User
, and Credentials
are:
MyUser.id
is anumber
(while loopback'sUser.id
is astring
)MyCredentials
has properties:identity
andsecret
(while loopback'sCredentials
has properties:email
andsecret
)MyUser.credential
is the relationship (instead of loopback'sUser.userCredentials
)
The issue is, when I am trying to bind (in application.ts
) with:
this.bind(UserServiceBindings.USER_SERVICE).toClass(MyUserService);
it would not work due to:
Argument of type 'typeof MyUserService' is not assignable to parameter of type 'Constructor<UserService<User, Credentials>>'.
Types of construct signatures are incompatible.
Type 'new (myUserRepository: MyUserRepository, passwordHasher: PasswordHasher<string>) => MyUserService' is not assignable to type 'new (...args: any[]) => UserService<User, Credentials>'.
Construct signature return types 'MyUserService' and 'UserService<User, Credentials>' are incompatible.
The types of 'verifyCredentials' are incompatible between these types.
Type '(myCredentials: MyCredentials) => Promise<MyUser>' is not assignable to type '(credentials: Credentials) => Promise<User>'.
Types of parameters 'myCredentials' and 'credentials' are incompatible.
Property 'identity' is missing in type 'Credentials' but required in type 'MyCredentials'.ts(2345)
myuser.repository.ts(8, 3): 'identity' is declared here.
In other words, it does not let me bind my custom UserService, unless I follow these rules:
- the property of the credential in user has to be exactly
userCredentials
- the credential has to have an
email
andpassword
property - the user's ID has to be in a
string
type - ...etc (probably missed much more constraints)
My question is:
How can I bind my custom user service, where I can customize what data is stored in the credentials
?