@Rotschaedl wrote:
I am new to Ionic and I need to send the following JSON post to my Backend Laravel application.
{ "user" : "amk1", "pwd" : "schule123" }
I am new to Ionic and I need to send the following JSON post to my Backend Laravel application.
{ "user" : "amk1", "pwd" : "schule123" }
I already tested it in Postman and i need to store the following JWT Token.
{"message":"success", "jwt":"token"}
First of all, how do I send the JSON request from ionic to the Laravel application i did it like this in the login.page.ts.
login(form) { this.authService.login(form.value).subscribe((res) => { this.router.navigateByUrl('home'); }); }
And in the auth.service.ts I wrote this.
export class AuthService { AUTH_SERVER_ADDRESS = 'http://127.0.0.1:8000/checklogin'; authSubject = new BehaviorSubject(false); register: any; constructor(private httpClient: HttpClient, private storage: Storage) { } login(user: User): Observable<AuthResponse> { return this.httpClient.post(`${this.AUTH_SERVER_ADDRESS}`, 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); } }) ); }
I get the following error when I try to login.
error: exception: "ErrorException" file: "/Users/rotschaedl/DPA/tischreservierenp/app/Http/Controllers/MainController.php" line: 124 message: "Undefined index: user" trace: (56) __proto__: Object
So what am I missing and how do I store the JWT token for the authentication.
Posts: 1
Participants: 1