fix call for login endpoint

This commit is contained in:
Thomas Peetz
2025-11-12 23:21:39 +01:00
parent 447030533f
commit 8ca73b94aa
3 changed files with 18 additions and 19 deletions
-1
View File
@@ -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';
@@ -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<TokenData>('http://localhost:8800/signup',
@@ -44,11 +40,15 @@ export class AuthService {
}));
}
login(email: string, password: string) {
return this.http.post<TokenData>('http://127.0.0.1:8800/api/login/token',
login(email: string, password: string): Observable<TokenData> {
const params = new HttpParams()
.set('username', email)
.append('password', password);
return this.http.post<TokenData>('http://127.0.0.1:8800/api/login/token', params,
{
username: email,
password: password
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
}
}
);
}
+5 -5
View File
@@ -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();
}
}