logging & feedback
This commit is contained in:
@@ -3,7 +3,6 @@ import { Component, inject } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { FormControl, FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
import { environment } from '../../../environments/environment';
|
||||
import { HotToastService } from '@ngxpert/hot-toast';
|
||||
|
||||
@Component({
|
||||
@@ -23,6 +22,8 @@ export class LoginComponent {
|
||||
client: string = "";
|
||||
client_id = null;
|
||||
|
||||
isLoading = false;
|
||||
|
||||
loginForm = new FormGroup({
|
||||
username: new FormControl(''),
|
||||
password: new FormControl(''),
|
||||
@@ -37,7 +38,7 @@ export class LoginComponent {
|
||||
const id = window.localStorage.getItem("auth_sesion_key");
|
||||
if (!id ||id.length < 2) { return; }
|
||||
|
||||
this.http.post(environment.api_url + 'auth/login-with-session-id', {
|
||||
this.http.post('api/auth/login-with-session-id', {
|
||||
code: id,
|
||||
client_id: this.client_id
|
||||
}).pipe(
|
||||
@@ -64,7 +65,7 @@ export class LoginComponent {
|
||||
this.redirectUri = params.redirect_uri;
|
||||
this.client_id = params.client_id;
|
||||
|
||||
this.http.get<any>(environment.api_url + 'auth/', {
|
||||
this.http.get<any>('api/auth/', {
|
||||
params
|
||||
}).subscribe({
|
||||
next: (client) => {
|
||||
@@ -78,8 +79,16 @@ export class LoginComponent {
|
||||
}
|
||||
|
||||
login() {
|
||||
this.toast.loading('Logging in...');
|
||||
this.http.post(environment.api_url + 'auth/login?'+ 'client_id=' + this.client_id, this.loginForm.value).subscribe({
|
||||
this.isLoading = true;
|
||||
this.http.post('api/auth/login?'+ 'client_id=' + this.client_id, this.loginForm.value).
|
||||
pipe(
|
||||
this.toast.observe({
|
||||
loading: 'Logging in...',
|
||||
success: 'Login successfull',
|
||||
error: 'Invalid login'
|
||||
})
|
||||
)
|
||||
.subscribe({
|
||||
next: (data) => {
|
||||
if (data["code"] != null) {
|
||||
window.localStorage.setItem("auth_sesion_key", data["session_key"]);
|
||||
@@ -88,7 +97,7 @@ export class LoginComponent {
|
||||
},
|
||||
error: (error) => {
|
||||
console.error(error);
|
||||
this.toast.error('Invalid login');
|
||||
this.isLoading = false;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user