diff --git a/kontor-angular/src/app/app.config.ts b/kontor-angular/src/app/app.config.ts index 97842c8..5c2022a 100644 --- a/kontor-angular/src/app/app.config.ts +++ b/kontor-angular/src/app/app.config.ts @@ -1,6 +1,5 @@ import { ApplicationConfig, provideBrowserGlobalErrorListeners, provideZoneChangeDetection } from '@angular/core'; import { provideRouter, withComponentInputBinding } from '@angular/router'; - import { routes } from './app.routes'; import { provideHttpClient } from '@angular/common/http'; diff --git a/kontor-angular/src/app/common/auth/auth-service.ts b/kontor-angular/src/app/common/auth/auth-service.ts index 712de07..27d9035 100644 --- a/kontor-angular/src/app/common/auth/auth-service.ts +++ b/kontor-angular/src/app/common/auth/auth-service.ts @@ -1,6 +1,6 @@ -import { HttpClient } from '@angular/common/http'; -import { Injectable } from '@angular/core'; -import { catchError, throwError } from 'rxjs'; +import { HttpClient, HttpParams } from '@angular/common/http'; +import { inject, Injectable } from '@angular/core'; +import { catchError, Observable, throwError } from 'rxjs'; interface AuthResponseData { @@ -16,13 +16,9 @@ export interface TokenData { token_type: string; } -@Injectable({ - providedIn: 'root' -}) +@Injectable({providedIn: 'root'}) export class AuthService { - constructor(private http: HttpClient) { - - } + private http = inject(HttpClient); signup(email: string, password: string) { return this.http.post('http://localhost:8800/signup', @@ -44,11 +40,15 @@ export class AuthService { })); } - login(email: string, password: string) { - return this.http.post('http://127.0.0.1:8800/api/login/token', + login(email: string, password: string): Observable { + const params = new HttpParams() + .set('username', email) + .append('password', password); + return this.http.post('http://127.0.0.1:8800/api/login/token', params, { - username: email, - password: password + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + } } ); } diff --git a/kontor-angular/src/app/common/auth/auth.ts b/kontor-angular/src/app/common/auth/auth.ts index c6ad305..f2113a1 100644 --- a/kontor-angular/src/app/common/auth/auth.ts +++ b/kontor-angular/src/app/common/auth/auth.ts @@ -39,16 +39,16 @@ export class Auth { authObservable = this.authService.signup(email, password) } - authObservable.subscribe( - token => { + authObservable.subscribe({ + next: token => { console.log(token); - this.isLoading = false; + this.isLoading = false; }, - (err: HttpErrorResponse) => { + error: err => { console.log(err); this.isLoading = false; } - ); + }); form.reset(); } }