Skip to content

Commit

Permalink
Small improvements
Browse files Browse the repository at this point in the history
1. Adding debugger for non production environments for oidc client.
2. Improve the timing when the UserManager is triggered to reload the session.
3. Suppress false-positive error logging after deleted IFrame
  • Loading branch information
blaubaer committed Jan 24, 2024
1 parent 32ec81a commit 6cbef98
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
uses: cloudflare/[email protected]
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
command: pages publish --project-name=demo-engity-green dist/app-green
command: pages deploy --project-name=demo-engity-green dist/app-green

deploy-red:
name: "Deploy: red"
Expand All @@ -75,5 +75,5 @@ jobs:
uses: cloudflare/[email protected]
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
command: pages publish --project-name=demo-engity-red dist/app-red
command: pages deploy --project-name=demo-engity-red dist/app-red

14 changes: 9 additions & 5 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,20 @@ import { AppTranslateLoader } from './core/i18n';

class NgErrorHandler implements ErrorHandler {
handleError(error) {
let foo = 'bar';
if (
unloaded &&
'rejection' in error &&
error.rejection &&
'message' in error.rejection &&
error.rejection.message === 'Failed to fetch'
((!error?.rejection && error?.message === 'Failed to fetch') ||
error?.rejection?.message === 'Failed to fetch')
) {
// Fetch error after unloading the window could happen is will be silently ignored.
} else {
console.error(error);
console.error(error, {
unloaded: unloaded,
rejection: error?.rejection,
message: error?.rejection?.message,
foo: foo,
});
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/app/core/components/after-login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export class AfterLoginComponent extends BasePageComponent implements OnInit {

async ngOnInit() {
await super.ngOnInit();
if (!this.silent) {
await this._authService.initialize();
}

const variant = await firstValueFrom(this.variant);
try {
await this._authService.loginCallback(this.silent);
Expand Down
3 changes: 3 additions & 0 deletions src/app/core/components/after-logout.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export class AfterLogoutComponent extends BasePageComponent implements OnInit {

async ngOnInit() {
await super.ngOnInit();
if (!this.silent) {
await this._authService.initialize();
}
const variant = await firstValueFrom(this.variant);
await this._authService.logoutCallback(this.silent);
await this._router.navigate(['/' + variant.subPath]);
Expand Down
17 changes: 14 additions & 3 deletions src/app/core/services/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { Injectable, OnDestroy } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { ErrorResponse, OidcMetadata, User, UserManager, WebStorageStateStore } from 'oidc-client-ts';
import { ErrorResponse, Log, OidcMetadata, User, UserManager, WebStorageStateStore } from 'oidc-client-ts';
import { concat, firstValueFrom, map, Observable, of, Subject, Subscription } from 'rxjs';
import { environment } from 'src/environments/environment';
import { Variant, VariantService } from './variant.service';

if (!environment.production) {
Log.setLogger(console);
Log.setLevel(Log.DEBUG);
}

@Injectable({
providedIn: 'root',
})
Expand All @@ -17,6 +22,7 @@ export class AuthService implements OnDestroy {

private readonly _variantSubscription: Subscription;

private _initializeTriggered: boolean = false;
private _initializedRaw: boolean = false;
private readonly _initializedSubject = new Subject<boolean>();

Expand All @@ -30,11 +36,15 @@ export class AuthService implements OnDestroy {
this._variantSubscription = this._variantService.active.subscribe((variant) =>
this._switchUserManagerAssignment(variant),
);
}

this.renew().then(() => {
public async initialize(): Promise<void> {
if (!this._initializeTriggered) {
this._initializeTriggered = true;
await this.renew();
this._initializedRaw = true;
this._initializedSubject.next(true);
});
}
}

private _createUserManagerAssignmentFor(variant: Variant): UserManagerAssignment {
Expand All @@ -45,6 +55,7 @@ export class AuthService implements OnDestroy {
redirect_uri: `${uriPrefix}after-login`,
silent_redirect_uri: `${uriPrefix}after-silent-login`,
response_type: 'code',
silentRequestTimeoutInSeconds: 5000,
scope: 'openid profile email contacts',
userStore: new WebStorageStateStore({
prefix: `${variant ? variant.key : ''}.`,
Expand Down

0 comments on commit 6cbef98

Please sign in to comment.