#I have a problem with data and hash arguments

51 messages · Page 1 of 1 (latest)

gusty mica
#

you'll need to find out why login method is called twice
Those snippets looks fine

loud flame
#

but the log pw login functie api is not called twice

#

so i dont think it is login thats called twice

gusty mica
#

ok

#

I didn't get why you have two logs of hashed and validateuser same password then

#

actually, validateUser is called twice, I guess

#

not sure why

loud flame
#

i am confused, and is this why the error happens?

gusty mica
#

your validateUser seems to be called twice
And we can't tell why

#

in its second call, you have password === undefined

#

and that's why bcrypt.compare will raise that error

loud flame
#

i checked but i never call it twice

#

i will make github

gusty mica
loud flame
#

ye but i have this log twice

#

so i dont know why this happens twice

#

i know its called twice thats why i am asking help
because the second call is undefined but i never do a second call

gusty mica
#

isn´t that due to some error on the client side?
Did you double checked if the client is making the right request?

#

I didn´t see anything wrong with your server code so far

loud flame
#

yes i did check

#

wait i can send part of client code whats happening

#
 onSubmit() {
    this.submitted = true;
    this.loading = true;

    this.mymodel.username = this.loginForm.get('username')?.value;
    this.mymodel.password = this.loginForm.get('password')?.value;
    console.log(this.mymodel);

    this.authService.login(this.mymodel).subscribe((response) => {
      console.log('werkt');
      const token = response.token;

      this.handleToken(token);
      this.router.navigate(['invoicing']);
    });

  }
  private handleToken(token: string): void {
    localStorage.setItem('token', token);
    this.authService.token = token;
  }```
```ts
  login(loginUser: Loginmodel): Observable<any> {
    return this.http
      .post<any>(`${this.apiUrl}/login`, loginUser, this.getHttpOptions())
      .pipe(
        map((response) => {
          localStorage.setItem('token', response.access_token);
          return { token: response.access_token };
        }),
        catchError((error: HttpErrorResponse) => {
          if (error.status === 409) {
            const errorMessage =
              'There is a problem with the token, if this keeps happening contact the server admin';
            throw new Error(errorMessage);
          }
          throw new Error('Something went wrong');
        })
      );
  }

i do get in the invoicing page that i want to go, just cant acces my data havving the guard
because this error

gusty mica
#

Right. And that error is due password being undefined

loud flame
#

ye

#

but it cant be undefined by client side because i checked it enough

gusty mica
#

somehow, it is

#

by reading your code I didn't find why tho

loud flame
#

sad should i post some client side parts to?

gusty mica
# gusty mica

I still didn't get how you manage to get the logs from validateUser method called twice

loud flame
#

same

#

thats why i am asking help

gusty mica
#

are you using some strategy from passport? I saw them in your repo but looks like users controller didn't use them

loud flame
#

yes i use them

#

just didn't send that code cus it was not important

gusty mica
#

I'd investigate here

#

see if username and password are what you think they are, in both file above

loud flame
#

doing that now

#

this is undefined

gusty mica
#

what's the value of payload?

loud flame
#

this one wont even get printed

gusty mica
#

right, the payload is the jwt, not its the decoded value

#

so there's something wrong with this or with the request you're sending from the client

loud flame
#

how do i check if thats whats wrong?

#

can i log that?

gusty mica
#

you could read the docs on that ExtractJwt. thing

#

see you're making a proper request

loud flame
#

i am

loud flame
#

i dont know whats wrong