dashboard
This commit is contained in:
52
idp_client/src/app/dashboard/dashboard.component.ts
Normal file
52
idp_client/src/app/dashboard/dashboard.component.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Component, inject, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { User } from '../model/user.interface';
|
||||
|
||||
@Component({
|
||||
selector: 'app-dashboard',
|
||||
standalone: true,
|
||||
imports: [],
|
||||
templateUrl: './dashboard.component.html',
|
||||
styleUrl: './dashboard.component.scss'
|
||||
})
|
||||
export class DashboardComponent implements OnInit {
|
||||
private router: Router = inject(Router);
|
||||
private http: HttpClient = inject(HttpClient);
|
||||
private user: User;
|
||||
|
||||
accessToken: string;
|
||||
|
||||
|
||||
ngOnInit(): void {
|
||||
|
||||
const refresh = sessionStorage.getItem('access');
|
||||
if (!refresh || refresh.length == 0) {
|
||||
this.router.navigate(['login']);
|
||||
} else {
|
||||
this.accessToken = refresh;
|
||||
this.refreshToken(refresh);
|
||||
this.getClients();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
refreshToken(token: string) {
|
||||
this.http.post('api/auth/verify', { access_token: token}).subscribe({
|
||||
next: res => {
|
||||
console.log(res)
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
getClients() {
|
||||
this.http.get('api/client', {headers: { auth: 'Bearer ' + this.accessToken}}).subscribe({
|
||||
next: result => {
|
||||
console.log(result);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user