fix: fix auto accessToken renew

This commit is contained in:
2025-06-15 02:48:48 +08:00
parent 1b5bdadf10
commit a2254bbe80
6 changed files with 36 additions and 38 deletions

View File

@@ -1,16 +1,20 @@
import type { RouterContext } from '@/infra/routes/traits';
import type { ParsedLocation } from '@tanstack/react-router';
import { firstValueFrom } from 'rxjs';
import { authContextFromInjector } from './context';
export const beforeLoadGuard = async ({
context,
}: { context: RouterContext }) => {
location,
}: { context: RouterContext; location: ParsedLocation }) => {
const { isAuthenticated$, authProvider } = authContextFromInjector(
context.injector
);
if (!(await firstValueFrom(isAuthenticated$))) {
const isAuthenticated = await firstValueFrom(
authProvider.autoLoginPartialRoutesGuard()
authProvider.autoLoginPartialRoutesGuard({
location,
})
);
if (!isAuthenticated) {
throw !isAuthenticated;