Files
zitadel/console/src/app/services/statehandler.service.ts
T
22ba33c2ef feat(console): add stylelint scss, app redirecturi validation, user grant api change (#531)
* add custom validator for redirect inputs

* change http pattern, i18n

* throw out deprecated usergrant functions

* remove deprecation service

* show docs in app detail

* reorder data promises

* show redirect desc in app detail

* custom validator

* grant search filters

* rm animations

* add validation to app detail

* user grant udpate

* rm grantid from update req

* fix project member guard

* fix hasrole directive

* show validation errors, i18n

* fix router link from org members

* navitem padding

* mobile layout

* policy grid mobile layout

* rm unused background

* lint

* add stylelinter add to pipeline

* update stylelint rules

* lint unknown rule

* disable enable rules

* lint

* table style lint

* table classes

* fix stylelinter rule, lint

* overflow fix member detail

* common detail page

* user create, password, project grant detail clnup

* move meta styles

* lint

* password policy indicator

* lint

* fix org create

* common component for complexity view

* lint

* user grant filter

* Update console/src/assets/i18n/en.json

Co-authored-by: Florian Forster <[email protected]>

* Update console/src/assets/i18n/en.json

Co-authored-by: Florian Forster <[email protected]>

* Update console/src/assets/i18n/de.json

Co-authored-by: Florian Forster <[email protected]>

* Update console/src/assets/i18n/de.json

Co-authored-by: Florian Forster <[email protected]>

* Update console/src/assets/i18n/en.json

Co-authored-by: Florian Forster <[email protected]>

Co-authored-by: Florian Forster <[email protected]>
2020-07-30 16:54:15 +02:00

60 lines
1.9 KiB
TypeScript

import { Injectable, Injector, OnDestroy, Type } from '@angular/core';
import { GuardsCheckStart, Router, RouterEvent } from '@angular/router';
import { OAuthService } from 'angular-oauth2-oidc';
import { Observable, Subject, throwError } from 'rxjs';
import { filter, map, shareReplay, switchMap, take, takeUntil } from 'rxjs/operators';
import { StatehandlerProcessorService } from './statehandler-processor.service';
export abstract class StatehandlerService {
public abstract createState(): Observable<string | undefined>;
public abstract initStateHandler(): void;
}
@Injectable()
export class StatehandlerServiceImpl
implements StatehandlerService, OnDestroy {
private events?: Observable<string>;
private unsubscribe$: Subject<void> = new Subject();
constructor(
oauthService: OAuthService,
private injector: Injector,
private processor: StatehandlerProcessorService,
) {
oauthService.events
.pipe(
filter(event => event.type === 'token_received'),
map(() => oauthService.state),
takeUntil(this.unsubscribe$),
)
.subscribe(state => processor.restoreState(state));
}
public initStateHandler(): void {
const router = this.injector.get(Router as Type<Router>);
this.events = (router.events as Observable<RouterEvent>).pipe(
filter(event => event instanceof GuardsCheckStart),
map(event => event.url),
shareReplay(1),
);
this.events.pipe(takeUntil(this.unsubscribe$)).subscribe();
}
public createState(): Observable<string | undefined> {
if (this.events === undefined) {
return throwError('no router events');
}
return this.events.pipe(
take(1),
switchMap(url => this.processor.createState(url)),
);
}
public ngOnDestroy(): void {
this.unsubscribe$.next();
}
}