feat: implement authentication flow and dynamic API configuration #5
This commit is contained in:
23
Web/src/app/content/content.ts
Normal file
23
Web/src/app/content/content.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { JsonPipe } from '@angular/common';
|
||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
import { Component, isDevMode, signal } from '@angular/core';
|
||||
import { OAuthService } from 'angular-oauth2-oidc';
|
||||
import { AppConfigService } from '../services/config.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-content',
|
||||
imports: [JsonPipe],
|
||||
templateUrl: './content.html',
|
||||
styleUrl: './content.scss'
|
||||
})
|
||||
export class Content {
|
||||
data = signal({});
|
||||
|
||||
constructor(httpClient: HttpClient, readonly as: OAuthService, readonly cs: AppConfigService) {
|
||||
httpClient.get((isDevMode() ? cs.setting.apiEndpoint : '') + '/api/product', {
|
||||
headers: new HttpHeaders({ Authorization: `Bearer ${as.getAccessToken()}` }).append('Content-Type', 'application/json')
|
||||
}).subscribe(data => {
|
||||
this.data.set(data);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user