mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-03 16:49:08 +00:00
44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
import { OnModuleInit, Inject } from '@nestjs/common';
|
|
import { ClientGrpc } from '@nestjs/microservices';
|
|
|
|
import { CognitoServiceInterface } from '@victorradael/protospack';
|
|
|
|
import { ILogin } from './interfaces';
|
|
|
|
export class AuthClientService implements OnModuleInit {
|
|
private cognitoService: CognitoServiceInterface;
|
|
constructor(
|
|
@Inject('AUTH_PACKAGE') private readonly grpcClient: ClientGrpc,
|
|
) {}
|
|
|
|
onModuleInit() {
|
|
this.cognitoService = this.grpcClient.getService<CognitoServiceInterface>(
|
|
'CognitoProtoService',
|
|
);
|
|
}
|
|
|
|
async signIn({ username, password }: ILogin): Promise<any> {
|
|
console.log('CognitoClientService', 'SignIn');
|
|
|
|
const tokens = await new Promise((resolve, reject) => {
|
|
this.cognitoService.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;
|
|
}
|
|
}
|