Browse Source

fix abstract class variable's accessor & improve error message

pull/18577/head
masumulu28 3 years ago
parent
commit
b268c037f8
  1. 20
      npm/ng-packs/packages/core/src/lib/abstracts/auth-error-filter.ts
  2. 22
      npm/ng-packs/packages/core/src/lib/models/auth-events.ts
  3. 14
      npm/ng-packs/packages/oauth/src/lib/services/oauth-error-filter.service.ts

20
npm/ng-packs/packages/core/src/lib/abstracts/auth-error-filter.ts

@ -2,8 +2,8 @@ import { signal } from '@angular/core';
import { AuthErrorEvent, AuthErrorFilter } from '../models'; import { AuthErrorEvent, AuthErrorFilter } from '../models';
export abstract class AbstractAuthErrorFilter<T, E> { export abstract class AbstractAuthErrorFilter<T, E> {
readonly #filters = signal<Array<T>>([]); protected readonly _filters = signal<Array<T>>([]);
filters = this.#filters.asReadonly(); readonly filters = this._filters.asReadonly();
abstract get(id: string): T; abstract get(id: string): T;
abstract add(filter: T): void; abstract add(filter: T): void;
@ -16,19 +16,25 @@ export class AuthErrorFilterService<
T = AuthErrorEvent, T = AuthErrorEvent,
E = AuthErrorFilter, E = AuthErrorFilter,
> extends AbstractAuthErrorFilter<T, E> { > extends AbstractAuthErrorFilter<T, E> {
private warningMessage() {
console.error('You should add @abp/ng-oauth packages or create your own auth packages.');
}
get(id: string): T { get(id: string): T {
throw new Error('Import AbpOAuthModule from @abp/ng.oauth or custom implementation'); this.warningMessage();
throw new Error('not implemented');
} }
add(filter: T): void { add(filter: T): void {
throw new Error('Import AbpOAuthModule from @abp/ng.oauth or custom implementation'); this.warningMessage();
} }
patch(item: Partial<T>): void { patch(item: Partial<T>): void {
throw new Error('Import AbpOAuthModule from @abp/ng.oauth or custom implementation'); this.warningMessage();
} }
remove(id: string): void { remove(id: string): void {
throw new Error('Import AbpOAuthModule from @abp/ng.oauth or custom implementation'); this.warningMessage();
} }
run(event: E): boolean { run(event: E): boolean {
throw new Error('Import AbpOAuthModule from @abp/ng.oauth or custom implementation'); this.warningMessage();
throw new Error('not implemented');
} }
} }

22
npm/ng-packs/packages/core/src/lib/models/auth-events.ts

@ -26,35 +26,29 @@ export type EventType =
| 'token_revoke_error'; | 'token_revoke_error';
export abstract class AuthEvent { export abstract class AuthEvent {
readonly type: EventType; constructor(public readonly type: EventType) {
constructor(type: EventType) {
this.type = type; this.type = type;
} }
} }
export class AuthSuccessEvent extends AuthEvent { export class AuthSuccessEvent extends AuthEvent {
readonly info: any; constructor(public readonly type: EventType, public readonly info?: any) {
constructor(type: EventType, info?: any) {
super(type); super(type);
this.info = info;
} }
} }
export class AuthInfoEvent extends AuthEvent { export class AuthInfoEvent extends AuthEvent {
readonly info: any; constructor(public readonly type: EventType, public readonly info?: any) {
constructor(type: EventType, info?: any) {
super(type); super(type);
this.info = info;
} }
} }
export class AuthErrorEvent extends AuthEvent { export class AuthErrorEvent extends AuthEvent {
readonly reason: object; constructor(
readonly params: object; public readonly type: EventType,
constructor(type: EventType, reason: object, params?: object) { public readonly reason: object,
public readonly params?: object,
) {
super(type); super(type);
this.reason = reason;
this.params = params;
} }
} }

14
npm/ng-packs/packages/oauth/src/lib/services/oauth-error-filter.service.ts

@ -1,22 +1,18 @@
import { AbstractAuthErrorFilter, AuthErrorFilter } from '@abp/ng.core'; import { Injectable } from '@angular/core';
import { Injectable, signal } from '@angular/core';
import { OAuthErrorEvent } from 'angular-oauth2-oidc'; import { OAuthErrorEvent } from 'angular-oauth2-oidc';
import { AbstractAuthErrorFilter, AuthErrorFilter } from '@abp/ng.core';
@Injectable({ providedIn: 'root' }) @Injectable({ providedIn: 'root' })
export class OAuthErrorFilterService extends AbstractAuthErrorFilter< export class OAuthErrorFilterService extends AbstractAuthErrorFilter<
AuthErrorFilter<OAuthErrorEvent>, AuthErrorFilter<OAuthErrorEvent>,
OAuthErrorEvent OAuthErrorEvent
> { > {
readonly #filters = signal<Array<AuthErrorFilter<OAuthErrorEvent>>>([]);
filters = this.#filters.asReadonly();
get(id: string): AuthErrorFilter<OAuthErrorEvent> { get(id: string): AuthErrorFilter<OAuthErrorEvent> {
return this.#filters().find(({ id: _id }) => _id === id); return this._filters().find(({ id: _id }) => _id === id);
} }
add(filter: AuthErrorFilter<OAuthErrorEvent>): void { add(filter: AuthErrorFilter<OAuthErrorEvent>): void {
this.#filters.update(items => [...items, filter]); this._filters.update(items => [...items, filter]);
} }
patch(item: Partial<AuthErrorFilter<OAuthErrorEvent>>): void { patch(item: Partial<AuthErrorFilter<OAuthErrorEvent>>): void {
@ -34,7 +30,7 @@ export class OAuthErrorFilterService extends AbstractAuthErrorFilter<
return; return;
} }
this.#filters.update(items => items.filter(({ id: _id }) => _id !== id)); this._filters.update(items => items.filter(({ id: _id }) => _id !== id));
} }
run(event: OAuthErrorEvent): boolean { run(event: OAuthErrorEvent): boolean {

Loading…
Cancel
Save