From faeec106efec3353ba2db8a3df597d85023d4711 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 24 Mar 2021 11:34:31 +0100 Subject: Add auth user client hook actions --- client/src/app/core/plugins/hooks.service.ts | 18 +++++++++++++++++- client/src/app/core/plugins/plugin.service.ts | 6 ++++++ 2 files changed, 23 insertions(+), 1 deletion(-) (limited to 'client/src/app/core/plugins') diff --git a/client/src/app/core/plugins/hooks.service.ts b/client/src/app/core/plugins/hooks.service.ts index ec47aa48c..ddde198d2 100644 --- a/client/src/app/core/plugins/hooks.service.ts +++ b/client/src/app/core/plugins/hooks.service.ts @@ -3,13 +3,29 @@ import { mergeMap, switchMap } from 'rxjs/operators' import { Injectable } from '@angular/core' import { PluginService } from '@app/core/plugins/plugin.service' import { ClientActionHookName, ClientFilterHookName, PluginClientScope } from '@shared/models' +import { AuthService, AuthStatus } from '../auth' type RawFunction = (params: U) => T type ObservableFunction = RawFunction> @Injectable() export class HooksService { - constructor (private pluginService: PluginService) { } + constructor ( + private authService: AuthService, + private pluginService: PluginService + ) { + // Run auth hooks + this.authService.userInformationLoaded + .subscribe(() => this.runAction('action:auth-user.information-loaded', 'common', { user: this.authService.getUser() })) + + this.authService.loginChangedSource.subscribe(obj => { + if (obj === AuthStatus.LoggedIn) { + this.runAction('action:auth-user.logged-in', 'common') + } else if (obj === AuthStatus.LoggedOut) { + this.runAction('action:auth-user.logged-out', 'common') + } + }) + } wrapObsFun diff --git a/client/src/app/core/plugins/plugin.service.ts b/client/src/app/core/plugins/plugin.service.ts index b755fda2c..54dba5e17 100644 --- a/client/src/app/core/plugins/plugin.service.ts +++ b/client/src/app/core/plugins/plugin.service.ts @@ -235,6 +235,12 @@ export class PluginService implements ClientHook { .toPromise() }, + getServerConfig: () => { + return this.server.getConfig() + .pipe(catchError(res => this.restExtractor.handleError(res))) + .toPromise() + }, + isLoggedIn: () => { return this.authService.isLoggedIn() }, -- cgit v1.2.3