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';
export abstract class AbstractAuthErrorFilter<T, E> {
readonly #filters = signal<Array<T>>([]);
filters = this.#filters.asReadonly();
protected readonly _filters = signal<Array<T>>([]);
readonly filters = this._filters.asReadonly();
abstract get(id: string): T;
abstract add(filter: T): void;
@ -16,19 +16,25 @@ export class AuthErrorFilterService<
T = AuthErrorEvent,
E = AuthErrorFilter,
> 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 {
throw new Error('Import AbpOAuthModule from @abp/ng.oauth or custom implementation');
this.warningMessage();
throw new Error('not implemented');
}
add(filter: T): void {
throw new Error('Import AbpOAuthModule from @abp/ng.oauth or custom implementation');
this.warningMessage();
}
patch(item: Partial<T>): void {
throw new Error('Import AbpOAuthModule from @abp/ng.oauth or custom implementation');
this.warningMessage();
}
remove(id: string): void {
throw new Error('Import AbpOAuthModule from @abp/ng.oauth or custom implementation');
this.warningMessage();
}
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';
export abstract class AuthEvent {
readonly type: EventType;
constructor(type: EventType) {
constructor(public readonly type: EventType) {
this.type = type;
}
}
export class AuthSuccessEvent extends AuthEvent {
readonly info: any;
constructor(type: EventType, info?: any) {
constructor(public readonly type: EventType, public readonly info?: any) {
super(type);
this.info = info;
}
}
export class AuthInfoEvent extends AuthEvent {
readonly info: any;
constructor(type: EventType, info?: any) {
constructor(public readonly type: EventType, public readonly info?: any) {
super(type);
this.info = info;
}
}
export class AuthErrorEvent extends AuthEvent {
readonly reason: object;
readonly params: object;
constructor(type: EventType, reason: object, params?: object) {
constructor(
public readonly type: EventType,
public readonly reason: object,
public readonly params?: object,
) {
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, signal } from '@angular/core';
import { Injectable } from '@angular/core';
import { OAuthErrorEvent } from 'angular-oauth2-oidc';
import { AbstractAuthErrorFilter, AuthErrorFilter } from '@abp/ng.core';
@Injectable({ providedIn: 'root' })
export class OAuthErrorFilterService extends AbstractAuthErrorFilter<
AuthErrorFilter<OAuthErrorEvent>,
OAuthErrorEvent
> {
readonly #filters = signal<Array<AuthErrorFilter<OAuthErrorEvent>>>([]);
filters = this.#filters.asReadonly();
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 {
this.#filters.update(items => [...items, filter]);
this._filters.update(items => [...items, filter]);
}
patch(item: Partial<AuthErrorFilter<OAuthErrorEvent>>): void {
@ -34,7 +30,7 @@ export class OAuthErrorFilterService extends AbstractAuthErrorFilter<
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 {

Loading…
Cancel
Save