mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-05-03 00:37:48 +08:00
Fix: persist SSO auth token on root route loader (#12784)
### What problem does this PR solve? This PR fixes SSO/OIDC login persistence after the Vite migration #12568. Because wrappers are ignored by React Router, the OAuth callback never stored the auth token in localStorage, causing auth to only work while ?auth= stayed in the URL. We move that logic into a route loader and remove the Bearer prefix for the signed token so the backend accepts it. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) Contribution during my time at RAGcon GmbH. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This commit is contained in:
@ -1,7 +1,8 @@
|
||||
import { lazy, memo, Suspense } from 'react';
|
||||
import { createBrowserRouter, Navigate, type RouteObject } from 'react-router';
|
||||
import { createBrowserRouter, Navigate, redirect, type RouteObject } from 'react-router';
|
||||
import FallbackComponent from './components/fallback-component';
|
||||
import { IS_ENTERPRISE } from './pages/admin/utils';
|
||||
import authorizationUtil from './utils/authorization-util';
|
||||
|
||||
export enum Routes {
|
||||
Root = '/',
|
||||
@ -141,7 +142,16 @@ const routeConfigOptions = [
|
||||
path: Routes.Root,
|
||||
layout: false,
|
||||
Component: () => import('@/layouts/next'),
|
||||
wrappers: ['@/wrappers/auth'],
|
||||
loader: ({ request }) => {
|
||||
const url = new URL(request.url);
|
||||
const auth = url.searchParams.get('auth');
|
||||
if (auth) {
|
||||
authorizationUtil.setAuthorization(auth);
|
||||
url.searchParams.delete('auth');
|
||||
return redirect(`${url.pathname}${url.search}`);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: Routes.Root,
|
||||
|
||||
@ -49,9 +49,7 @@ const storage = {
|
||||
|
||||
export const getAuthorization = () => {
|
||||
const auth = getSearchValue('auth');
|
||||
const authorization = auth
|
||||
? 'Bearer ' + auth
|
||||
: storage.getAuthorization() || '';
|
||||
const authorization = auth ? auth : storage.getAuthorization() || '';
|
||||
|
||||
return authorization;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user