mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-13 21:09:08 +00:00
47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
import { OnModuleInit, Inject } from '@nestjs/common';
|
|
import { ClientGrpc } from '@nestjs/microservices';
|
|
|
|
import {
|
|
AuthServiceInterface,
|
|
DucServicesNames,
|
|
} from '@victorradael/protospack';
|
|
|
|
import { ILogin } from './interfaces';
|
|
|
|
export class AuthClientService implements OnModuleInit {
|
|
private authService: AuthServiceInterface;
|
|
constructor(
|
|
@Inject('AUTH_PACKAGE') private readonly grpcClient: ClientGrpc,
|
|
) {}
|
|
|
|
onModuleInit() {
|
|
this.authService = this.grpcClient.getService<AuthServiceInterface>(
|
|
DucServicesNames.AuthProtoService,
|
|
);
|
|
}
|
|
|
|
async signIn({ username, password }: ILogin): Promise<any> {
|
|
console.log('AuthClientService', 'SignIn');
|
|
|
|
const tokens = await new Promise((resolve, reject) => {
|
|
this.authService.signIn({ username, password }).subscribe({
|
|
next(x) {
|
|
resolve(x);
|
|
},
|
|
error(err) {
|
|
console.log('Observable Error');
|
|
reject(err);
|
|
},
|
|
complete() {
|
|
console.log('done');
|
|
},
|
|
});
|
|
})
|
|
.then((res) => res)
|
|
.catch((err) => {
|
|
throw new Error(err);
|
|
});
|
|
return tokens;
|
|
}
|
|
}
|