Search code examples
laravelangular7ionic4

Ionic 4 & Laravel API - Getting null response on http request


I'm developing a mobile app in Ionic 4. But I don't know why I'm getting a null response from the API. The API is made on Laravel and works fine in postman.

Here is my code.

auth.service.ts

login(user: User): Observable<AuthResponse> {
    return this.httpClient.post(`${this.AUTH_SERVER_ADDRESS}/login`, user)
    .pipe(
        tap(async (res: AuthResponse) => {
            if (res.user) {
                await this.storage.set("ACCESS_TOKEN", res.user.access_token);
                await this.storage.set("EXPIRES_IN", res.user.expires_in);
                this.authSubject.next(true);
            }
        })
    );
}

login.page.ts

login(form){
    this.authService.login(form.value)
    .subscribe((res)=>{
        this.router.navigateByUrl('home');
    });
}

Here is my request screenshot from dev tools:

enter image description here

I would greatly appreciate it if someone can help me out. If you need other information or details, please let me know

Thanks!


Solution

  • The problem was from the API server. The headers for the respnse war wrong