Slight renaming
This commit is contained in:
parent
7cdf69533b
commit
5e367418d1
4 changed files with 11 additions and 12 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import {DestroyRef, effect, inject, Injectable, signal} from '@angular/core';
|
||||
import {computed, DestroyRef, inject, Injectable, signal} from '@angular/core';
|
||||
import {OAuthErrorEvent, OAuthService} from "angular-oauth2-oidc";
|
||||
import {BehaviorSubject, from, Observable} from "rxjs";
|
||||
import {from} from "rxjs";
|
||||
import {HttpClient} from "@angular/common/http";
|
||||
import {environment} from "../../environments/environment";
|
||||
import {OidcPublicConfig} from "../admin/_models/oidc-config";
|
||||
|
|
@ -34,11 +34,11 @@ export class OidcService {
|
|||
public readonly loaded = this._loaded.asReadonly();
|
||||
public readonly loaded$ = toObservable(this.loaded);
|
||||
|
||||
/**
|
||||
* OIDC discovery document has been loaded, login tried and OIDC has been set up
|
||||
*/
|
||||
private readonly _ready = signal(false);
|
||||
public readonly ready = this._ready.asReadonly();
|
||||
public readonly inUse = computed(() => {
|
||||
const loaded = this.loaded();
|
||||
const settings = this.settings();
|
||||
return loaded && settings && settings.authority.trim() !== '';
|
||||
});
|
||||
|
||||
/**
|
||||
* Public OIDC settings
|
||||
|
|
@ -96,7 +96,6 @@ export class OidcService {
|
|||
from(this.oauth2.loadDiscoveryDocumentAndTryLogin()).subscribe({
|
||||
next: _ => {
|
||||
this._loaded.set(true);
|
||||
this._ready.set(true);
|
||||
},
|
||||
error: error => {
|
||||
console.log(error);
|
||||
|
|
|
|||
|
|
@ -102,9 +102,9 @@ export class AppComponent implements OnInit {
|
|||
|
||||
// Login automatically when a token is available
|
||||
effect(() => {
|
||||
const ready = this.oidcService.ready();
|
||||
const inUse = this.oidcService.inUse();
|
||||
const user = this.accountService.currentUserSignal();
|
||||
if (!ready || !this.oidcService.token || user) return;
|
||||
if (!inUse || !this.oidcService.token || user) return;
|
||||
|
||||
this.accountService.loginByToken(this.oidcService.token).subscribe({
|
||||
next: () => {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
<ngx-extended-pdf-viewer
|
||||
#pdfViewer
|
||||
[src]="readerService.downloadPdf(this.chapterId)"
|
||||
[authorization]="'Bearer ' + user.oidcToken ?? user.token"
|
||||
[authorization]="'Bearer ' + (user.oidcToken ?? user.token)"
|
||||
height="100vh"
|
||||
[(page)]="currentPage"
|
||||
[textLayer]="true"
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@
|
|||
</form>
|
||||
}
|
||||
|
||||
@if (oidcService.ready()) {
|
||||
@if (oidcService.inUse()) {
|
||||
<button
|
||||
class="btn btn-outline-primary mt-2 d-flex align-items-center gap-2"
|
||||
(click)="oidcService.login()">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue