feat: add auth to webapi
This commit is contained in:
@@ -1,41 +0,0 @@
|
||||
import type { Observable } from '@graphiql/toolkit';
|
||||
import { InjectionToken, inject } from '@outposts/injection-js';
|
||||
import {
|
||||
type AuthFeature,
|
||||
EventTypes,
|
||||
PublicEventsService,
|
||||
} from 'oidc-client-rx';
|
||||
import { filter, shareReplay } from 'rxjs';
|
||||
|
||||
export type CheckAuthResultEventType =
|
||||
| { type: EventTypes.CheckingAuthFinished }
|
||||
| {
|
||||
type: EventTypes.CheckingAuthFinishedWithError;
|
||||
value: string;
|
||||
};
|
||||
export const CHECK_AUTH_RESULT_EVENT = new InjectionToken<
|
||||
Observable<CheckAuthResultEventType>
|
||||
>('CHECK_AUTH_RESULT_EVENT');
|
||||
|
||||
export function withCheckAuthResultEvent(): AuthFeature {
|
||||
return {
|
||||
ɵproviders: [
|
||||
{
|
||||
provide: CHECK_AUTH_RESULT_EVENT,
|
||||
useFactory: () => {
|
||||
const publishEventService = inject(PublicEventsService);
|
||||
|
||||
return publishEventService.registerForEvents().pipe(
|
||||
filter(
|
||||
(e) =>
|
||||
e.type === EventTypes.CheckingAuthFinishedWithError ||
|
||||
e.type === EventTypes.CheckingAuthFinished
|
||||
),
|
||||
shareReplay(1)
|
||||
);
|
||||
},
|
||||
deps: [PublicEventsService],
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { runInInjectionContext } from '@outposts/injection-js';
|
||||
import { autoLoginPartialRoutesGuard } from 'oidc-client-rx';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
import type { RouterContext } from '../controllers/__root';
|
||||
import type { RouterContext } from '../web/controller/__root';
|
||||
|
||||
export const beforeLoadGuard = async ({
|
||||
context,
|
||||
|
||||
Reference in New Issue
Block a user