Slight renaming

This commit is contained in:
Amelia 2025-07-08 20:06:01 +02:00
parent 7cdf69533b
commit 5e367418d1
4 changed files with 11 additions and 12 deletions

View file

@ -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);

View file

@ -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: () => {

View file

@ -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"

View file

@ -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()">