fix call for login endpoint
This commit is contained in:
@@ -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',
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user