0

I`m developing auth guard in nestjs, I got This error.

If I call .pipe()

        async validateUser(email: string, password: string): Promise<User> {
        const findUser = await this.userRepository.findOneBy({email: email, password: password });
        if (!findUser) throw new NotFoundException("user not found");
         return findUser;
        
    }

     login(user: User): Observable<string> {
        const { email, password } = user; 
        return this.validateUser(email, password).pipe(
            switchMap((user: User) =>  {
                if (user) {
                    // create JWT - credwntials
                    return from(this.jwtServices.signAsync({ user }));
                }
            }),
        );

    }

This my authService.

Anas Isah
  • 47
  • 7

1 Answers1

0

You need transform promise to observable using from()

import { from } from 'rxjs';

login(user: User): Observable<string> {
        const { email, password } = user; 
        return from(this.validateUser(email, password)).pipe(
            switchMap((user: User) =>  {
                if (user) {
                    // create JWT - credwntials
                    return from(this.jwtServices.signAsync({ user }));
                }
            }),
        );