Chore: Check for deprecations using eslint plugin
Chore: environment file replacement stopped. Chore: All components are now standalone and removed all modules Chore: App routing is now in app.routes and similarly for all submodules Chore: Http interceptors are now functional and split refresh interceptor into a separate one.
This commit is contained in:
1 parent
b6bb3dbcfd
commit
4571b31fc0
309 files changed
+3897
-5222
No files matched your search
@@ -3,7 +3,7 @@ import { Injectable } from '@angular/core';
|
||||
import { BehaviorSubject, Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { environment } from '../../environments/environment';
|
||||
import { environment } from '../app.environment';
|
||||
import { User } from '../core/user';
|
||||
|
||||
const loginUrl = '/token';
|
||||
@@ -14,6 +14,7 @@ const JWT_USER = 'JWT_USER';
|
||||
export class AuthService {
|
||||
public currentUser: Observable<User | null>;
|
||||
private currentUserSubject: BehaviorSubject<User | null> = new BehaviorSubject<User | null>(null);
|
||||
public isRefreshing = false;
|
||||
|
||||
constructor(private http: HttpClient) {
|
||||
this.checkStorage();
|
||||
@@ -82,19 +83,17 @@ export class AuthService {
|
||||
formData.append('password', password);
|
||||
formData.append('otp', '' + otp);
|
||||
formData.append('grant_type', 'password');
|
||||
return this.http
|
||||
.post<{ access_token: string; token_type: string }>(loginUrl, formData)
|
||||
.pipe(map((u) => u.access_token))
|
||||
.pipe(map((u) => AuthService.parseJwt(u)))
|
||||
.pipe(
|
||||
map((user) => {
|
||||
// Store user details and jwt token in local storage
|
||||
// to keep user logged in between page refreshes
|
||||
localStorage.setItem(JWT_USER, JSON.stringify(user));
|
||||
this.currentUserSubject.next(user);
|
||||
return user;
|
||||
}),
|
||||
);
|
||||
return this.http.post<{ access_token: string; token_type: string }>(loginUrl, formData).pipe(
|
||||
map((u) => u.access_token),
|
||||
map((u) => AuthService.parseJwt(u)),
|
||||
map((user) => {
|
||||
// Store user details and jwt token in local storage
|
||||
// to keep user logged in between page refreshes
|
||||
localStorage.setItem(JWT_USER, JSON.stringify(user));
|
||||
this.currentUserSubject.next(user);
|
||||
return user;
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
needsRefreshing(): boolean {
|
||||
@@ -112,19 +111,17 @@ export class AuthService {
|
||||
}
|
||||
|
||||
refreshToken() {
|
||||
return this.http
|
||||
.post<{ access_token: string; token_type: string }>(refreshUrl, {})
|
||||
.pipe(map((u) => u.access_token))
|
||||
.pipe(map((u) => AuthService.parseJwt(u)))
|
||||
.pipe(
|
||||
map((user) => {
|
||||
// Store user details and jwt token in local storage
|
||||
// to keep user logged in between page refreshes
|
||||
localStorage.setItem(JWT_USER, JSON.stringify(user));
|
||||
this.currentUserSubject.next(user);
|
||||
return user;
|
||||
}),
|
||||
);
|
||||
return this.http.post<{ access_token: string; token_type: string }>(refreshUrl, {}).pipe(
|
||||
map((u) => u.access_token),
|
||||
map((u) => AuthService.parseJwt(u)),
|
||||
map((user) => {
|
||||
// Store user details and jwt token in local storage
|
||||
// to keep user logged in between page refreshes
|
||||
localStorage.setItem(JWT_USER, JSON.stringify(user));
|
||||
this.currentUserSubject.next(user);
|
||||
return user;
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
allowed(permission: string): boolean {
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
|
||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { LoginComponent } from './login.component';
|
||||
|
||||
@@ -8,15 +6,11 @@ describe('LoginComponent', () => {
|
||||
let component: LoginComponent;
|
||||
let fixture: ComponentFixture<LoginComponent>;
|
||||
|
||||
beforeEach(waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [LoginComponent],
|
||||
imports: [RouterTestingModule],
|
||||
providers: [provideHttpClient(withInterceptorsFromDi())],
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [LoginComponent],
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(LoginComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
|
||||
import { FormControl, FormGroup, Validators } from '@angular/forms';
|
||||
import { FormControl, FormGroup, Validators, ReactiveFormsModule } from '@angular/forms';
|
||||
import { MatButton } from '@angular/material/button';
|
||||
import { MatCard, MatCardHeader, MatCardTitle, MatCardContent, MatCardActions } from '@angular/material/card';
|
||||
import { MatDivider } from '@angular/material/divider';
|
||||
import { MatFormField, MatLabel, MatSuffix } from '@angular/material/form-field';
|
||||
import { MatIcon } from '@angular/material/icon';
|
||||
import { MatInput } from '@angular/material/input';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
|
||||
import { ToasterService } from '../../core/toaster.service';
|
||||
@@ -10,6 +16,22 @@ import { AuthService } from '../auth.service';
|
||||
selector: 'app-login',
|
||||
templateUrl: './login.component.html',
|
||||
styleUrls: ['./login.component.css'],
|
||||
standalone: true,
|
||||
imports: [
|
||||
MatCard,
|
||||
MatCardHeader,
|
||||
MatCardTitle,
|
||||
MatCardContent,
|
||||
ReactiveFormsModule,
|
||||
MatFormField,
|
||||
MatLabel,
|
||||
MatInput,
|
||||
MatIcon,
|
||||
MatSuffix,
|
||||
MatDivider,
|
||||
MatCardActions,
|
||||
MatButton,
|
||||
],
|
||||
})
|
||||
export class LoginComponent implements OnInit, AfterViewInit {
|
||||
@ViewChild('nameElement', { static: true }) nameElement?: ElementRef;
|
||||
@@ -60,17 +82,17 @@ export class LoginComponent implements OnInit, AfterViewInit {
|
||||
this.auth
|
||||
.login(username, password, otp)
|
||||
// .pipe(first())
|
||||
.subscribe(
|
||||
() => {
|
||||
.subscribe({
|
||||
next: () => {
|
||||
this.router.navigateByUrl(this.returnUrl);
|
||||
},
|
||||
(error) => {
|
||||
error: (error) => {
|
||||
if (error.status === 401 && error.error.detail === 'Client is not registered') {
|
||||
this.showOtp = true;
|
||||
this.clientId = this.cs.getCookie('client_id');
|
||||
}
|
||||
this.toaster.show('Danger', error.error.details);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,4 @@
|
||||
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
|
||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { LogoutComponent } from './logout.component';
|
||||
|
||||
@@ -8,15 +6,11 @@ describe('LogoutComponent', () => {
|
||||
let component: LogoutComponent;
|
||||
let fixture: ComponentFixture<LogoutComponent>;
|
||||
|
||||
beforeEach(waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [LogoutComponent],
|
||||
imports: [RouterTestingModule],
|
||||
providers: [provideHttpClient(withInterceptorsFromDi())],
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [LogoutComponent],
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(LogoutComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
|
||||
@@ -7,6 +7,7 @@ import { AuthService } from '../auth.service';
|
||||
@Component({
|
||||
selector: 'app-logout',
|
||||
template: '',
|
||||
standalone: true,
|
||||
})
|
||||
export class LogoutComponent implements OnInit {
|
||||
constructor(
|
||||
|
||||
Reference in new issue
Block a user