Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

♻️ refactor(auth): consolidate auth SPA loading (#15903)

Innei99785d3cc7fa
diff --git a/src/features/Auth/OAuthConsent/InteractionDetailsSkeleton.tsx b/src/features/Auth/OAuthConsent/InteractionDetailsSkeleton.tsx
new file mode 100644
index 00000000000..38a3b6cf57f
--- /dev/null
+++ b/src/features/Auth/OAuthConsent/InteractionDetailsSkeleton.tsx
@@ -0,0 +1,45 @@
+'use client';
+
+import { Block, Flexbox, Skeleton } from '@lobehub/ui';
+import { memo } from 'react';
+
+import AuthCard from '@/features/AuthCard';
+
+const InteractionDetailsSkeleton = memo(() => (
+ <Flexbox gap={16} width={'min(100%,400px)'}>
+ <Flexbox horizontal align={'center'} justify={'center'} width={'100%'}>
+ <Skeleton.Avatar active shape={'square'} size={72} />
+ </Flexbox>
+ <AuthCard
+ title={<Skeleton.Button active block style={{ height: 40 }} />}
+ footer={
+ <Flexbox gap={12} width={'100%'}>
+ <Skeleton.Button active block size="large" />
+ <Skeleton.Button active block size="large" />
+ </Flexbox>
+ }
+ subtitle={
+ <Flexbox gap={8} width={'100%'}>
+ <Skeleton.Button active block style={{ height: 22 }} />
+ <Skeleton.Button active style={{ height: 22, width: '72%' }} />
+ </Flexbox>
+ }
+ >
+ <Flexbox gap={12} width={'100%'}>
+ <Skeleton.Button active style={{ height: 22, width: '54%' }} />
+ <Flexbox gap={8} width={'100%'}>
+ <Block padding={16} variant={'filled'}>
+ <Skeleton.Button active block />
+ </Block>
+ <Block padding={16} variant={'filled'}>
+ <Skeleton.Button active style={{ width: '68%' }} />
+ </Block>
+ </Flexbox>
+ </Flexbox>
+ </AuthCard>
+ </Flexbox>
+));
+
+InteractionDetailsSkeleton.displayName = 'OAuthInteractionDetailsSkeleton';
+
+export default InteractionDetailsSkeleton;
diff --git a/src/features/Auth/OAuthConsent/index.tsx b/src/features/Auth/OAuthConsent/index.tsx
index 4051e214622..d75e8012772 100644
--- a/src/features/Auth/OAuthConsent/index.tsx
+++ b/src/features/Auth/OAuthConsent/index.tsx
@@ -5,11 +5,11 @@ import { memo } from 'react';
import { useParams } from 'react-router-dom';
import NotFound from '@/components/404';
-import BrandTextLoading from '@/components/Loading/BrandTextLoading';
import OAuthGuard from '../OAuthGuard';
import ClientError from './ClientError';
import Consent from './Consent';
+import InteractionDetailsSkeleton from './InteractionDetailsSkeleton';
import Login from './Login';
import { InteractionDetailsError, useInteractionDetails } from './useInteractionDetails';
@@ -67,7 +67,7 @@ const InteractionContent = memo(() => {
if (!uid) return <NotFound />;
if (error) return renderError(error);
- if (isLoading || !data) return <BrandTextLoading debugId={'Auth > OAuthConsent'} />;
+ if (isLoading || !data) return <InteractionDetailsSkeleton />;
if (data.prompt === 'login') return <Login clientMetadata={data.clientMetadata} uid={data.uid} />;
diff --git a/src/routes/auth/auth-error/index.tsx b/src/routes/auth/auth-error/index.tsx
index a5e5e492555..0fb788764b1 100644
--- a/src/routes/auth/auth-error/index.tsx
+++ b/src/routes/auth/auth-error/index.tsx
@@ -1,3 +1 @@
-import AuthError from '@/features/Auth/AuthError';
-
-export default AuthError;
+export { default } from '@/features/Auth/AuthError';
diff --git a/src/routes/auth/market-auth-callback/index.tsx b/src/routes/auth/market-auth-callback/index.tsx
index 0ed2e7b2b77..ebc17edc6e3 100644
--- a/src/routes/auth/market-auth-callback/index.tsx
+++ b/src/routes/auth/market-auth-callback/index.tsx
@@ -1,3 +1 @@
-import MarketAuthCallback from '@/features/Auth/MarketAuthCallback';
-
-export default MarketAuthCallback;
+export { default } from '@/features/Auth/MarketAuthCallback';
diff --git a/src/routes/auth/oauth/callback/error/index.tsx b/src/routes/auth/oauth/callback/error/index.tsx
index 29633db5e31..7ef26a60af5 100644
--- a/src/routes/auth/oauth/callback/error/index.tsx
+++ b/src/routes/auth/oauth/callback/error/index.tsx
@@ -1,3 +1 @@
-import OAuthCallbackError from '@/features/Auth/OAuthCallback/Error';
-
-export default OAuthCallbackError;
+export { default } from '@/features/Auth/OAuthCallback/Error';
diff --git a/src/routes/auth/oauth/callback/social/index.tsx b/src/routes/auth/oauth/callback/social/index.tsx
index f45d822c817..838e1d134e2 100644
--- a/src/routes/auth/oauth/callback/social/index.tsx
+++ b/src/routes/auth/oauth/callback/social/index.tsx
@@ -1,3 +1 @@
-import OAuthCallbackSocial from '@/features/Auth/OAuthCallback/Social';
-
-export default OAuthCallbackSocial;
+export { default } from '@/features/Auth/OAuthCallback/Social';
diff --git a/src/routes/auth/oauth/callback/success/index.tsx b/src/routes/auth/oauth/callback/success/index.tsx
index b91168bf2fa..277bd04b87a 100644
--- a/src/routes/auth/oauth/callback/success/index.tsx
+++ b/src/routes/auth/oauth/callback/success/index.tsx
@@ -1,3 +1 @@
-import OAuthCallbackSuccess from '@/features/Auth/OAuthCallback/Success';
-
-export default OAuthCallbackSuccess;
+export { default } from '@/features/Auth/OAuthCallback/Success';
diff --git a/src/routes/auth/oauth/consent/[uid]/index.tsx b/src/routes/auth/oauth/consent/[uid]/index.tsx
index 3faa0a10e9b..71901d572a9 100644
--- a/src/routes/auth/oauth/consent/[uid]/index.tsx
+++ b/src/routes/auth/oauth/consent/[uid]/index.tsx
@@ -1,3 +1 @@
-import OAuthConsent from '@/features/Auth/OAuthConsent';
-
-export default OAuthConsent;
+export { default } from '@/features/Auth/OAuthConsent';
diff --git a/src/routes/auth/oauth/device/confirm/index.tsx b/src/routes/auth/oauth/device/confirm/index.tsx
index ab087413efe..09192502cff 100644
--- a/src/routes/auth/oauth/device/confirm/index.tsx
+++ b/src/routes/auth/oauth/device/confirm/index.tsx
@@ -1,3 +1 @@
-import DeviceConfirmPage from '@/features/Auth/OAuthDevice/DeviceConfirmPage';
-
-export default DeviceConfirmPage;
+export { default } from '@/features/Auth/OAuthDevice/DeviceConfirmPage';
diff --git a/src/routes/auth/oauth/device/index.tsx b/src/routes/auth/oauth/device/index.tsx
index f98ddf197b0..e47dc16a337 100644
--- a/src/routes/auth/oauth/device/index.tsx
+++ b/src/routes/auth/oauth/device/index.tsx
@@ -1,3 +1 @@
-import DeviceInputPage from '@/features/Auth/OAuthDevice/DeviceInputPage';
-
-export default DeviceInputPage;
+export { default } from '@/features/Auth/OAuthDevice/DeviceInputPage';
diff --git a/src/routes/auth/oauth/device/success/index.tsx b/src/routes/auth/oauth/device/success/index.tsx
index ad1a18f61f2..403ae72e6b1 100644
--- a/src/routes/auth/oauth/device/success/index.tsx
+++ b/src/routes/auth/oauth/device/success/index.tsx
@@ -1,3 +1 @@
-import DeviceSuccessPage from '@/features/Auth/OAuthDevice/DeviceSuccessPage';
-
-export default DeviceSuccessPage;
+export { default } from '@/features/Auth/OAuthDevice/DeviceSuccessPage';
diff --git a/src/routes/auth/reset-password/index.tsx b/src/routes/auth/reset-password/index.tsx
index d1d29559e5b..8d4fa9b8dc8 100644
--- a/src/routes/auth/reset-password/index.tsx
+++ b/src/routes/auth/reset-password/index.tsx
@@ -1,3 +1 @@
-import ResetPassword from '@/features/Auth/ResetPassword';
-
-export default ResetPassword;
+export { default } from '@/features/Auth/ResetPassword';
diff --git a/src/routes/auth/signin/index.tsx b/src/routes/auth/signin/index.tsx
index d21d7488fb1..1dfdf80a057 100644
--- a/src/routes/auth/signin/index.tsx
+++ b/src/routes/auth/signin/index.tsx
@@ -1,3 +1 @@
-import SignIn from '@/features/Auth/SignIn';
-
-export default SignIn;
+export { default } from '@/features/Auth/SignIn';
diff --git a/src/routes/auth/signup/index.tsx b/src/routes/auth/signup/index.tsx
index 94de63915db..b2569c8f170 100644
--- a/src/routes/auth/signup/index.tsx
+++ b/src/routes/auth/signup/index.tsx
@@ -1,3 +1 @@
-import SignUp from '@/features/Auth/SignUp';
-
-export default SignUp;
+export { default } from '@/features/Auth/SignUp';
diff --git a/src/routes/auth/verify-email/index.tsx b/src/routes/auth/verify-email/index.tsx
index 0c7a0afaa38..c3769110dbf 100644
--- a/src/routes/auth/verify-email/index.tsx
+++ b/src/routes/auth/verify-email/index.tsx
@@ -1,3 +1 @@
-import VerifyEmail from '@/features/Auth/VerifyEmail';
-
-export default VerifyEmail;
+export { default } from '@/features/Auth/VerifyEmail';
diff --git a/src/spa/router/authRouter.config.tsx b/src/spa/router/authRouter.config.tsx
index c06592903e3..622a15cb784 100644
--- a/src/spa/router/authRouter.config.tsx
+++ b/src/spa/router/authRouter.config.tsx
@@ -9,17 +9,10 @@ import AuthShell from '@/features/AuthShell';
import { isChunkLoadError, notifyChunkError } from '@/utils/chunkError';
// Local helper on purpose: @/utils/router's dynamicElement would pull SPAGlobalProvider/global store into the auth bundle
-const lazyElement = (
- importFn: () => Promise<{ default: ComponentType }>,
- debugId: string,
-): ReactElement => {
+const lazyElement = (importFn: () => Promise<{ default: ComponentType }>): ReactElement => {
const LazyComponent = lazy(importFn);
- return (
- <Suspense fallback={<Loading debugId={debugId} />}>
- <LazyComponent />
- </Suspense>
- );
+ return <LazyComponent />;
};
const buttonStyle: CSSProperties = {
@@ -82,82 +75,63 @@ export const authRoutes: RouteObject[] = [
{
children: [
{
- element: lazyElement(() => import('@/routes/auth/signin'), 'Auth > SignIn'),
+ element: lazyElement(() => import('@/routes/auth/signin')),
path: 'signin',
},
{
- element: lazyElement(() => import('@/routes/auth/signup'), 'Auth > SignUp'),
+ element: lazyElement(() => import('@/routes/auth/signup')),
path: 'signup',
},
{
- element: lazyElement(() => import('@/routes/auth/verify-email'), 'Auth > VerifyEmail'),
+ element: lazyElement(() => import('@/routes/auth/verify-email')),
path: 'verify-email',
},
{
- element: lazyElement(() => import('@/routes/auth/reset-password'), 'Auth > ResetPassword'),
+ element: lazyElement(() => import('@/routes/auth/reset-password')),
path: 'reset-password',
},
{
- element: lazyElement(() => import('@/routes/auth/auth-error'), 'Auth > AuthError'),
+ element: lazyElement(() => import('@/routes/auth/auth-error')),
path: 'auth-error',
},
{
- element: lazyElement(
- () => import('@/routes/auth/market-auth-callback'),
- 'Auth > MarketAuthCallback',
- ),
+ element: lazyElement(() => import('@/routes/auth/market-auth-callback')),
path: 'market-auth-callback',
},
{
- element: lazyElement(
- () => import('@/routes/auth/oauth/consent/[uid]'),
- 'Auth > OAuthConsent',
- ),
+ element: lazyElement(() => import('@/routes/auth/oauth/consent/[uid]')),
path: 'oauth/consent/:uid',
},
{
- element: lazyElement(() => import('@/routes/auth/oauth/device'), 'Auth > OAuthDevice'),
+ element: lazyElement(() => import('@/routes/auth/oauth/device')),
path: 'oauth/device',
},
{
- element: lazyElement(
- () => import('@/routes/auth/oauth/device/confirm'),
- 'Auth > OAuthDeviceConfirm',
- ),
+ element: lazyElement(() => import('@/routes/auth/oauth/device/confirm')),
path: 'oauth/device/confirm',
},
{
- element: lazyElement(
- () => import('@/routes/auth/oauth/device/success'),
- 'Auth > OAuthDeviceSuccess',
- ),
+ element: lazyElement(() => import('@/routes/auth/oauth/device/success')),
path: 'oauth/device/success',
},
{
- element: lazyElement(
- () => import('@/routes/auth/oauth/callback/success'),
- 'Auth > OAuthCallbackSuccess',
- ),
+ element: lazyElement(() => import('@/routes/auth/oauth/callback/success')),
path: 'oauth/callback/success',
},
{
- element: lazyElement(
- () => import('@/routes/auth/oauth/callback/social'),
- 'Auth > OAuthCallbackSocial',
- ),
+ element: lazyElement(() => import('@/routes/auth/oauth/callback/social')),
path: 'oauth/callback/social',
},
{
- element: lazyElement(
- () => import('@/routes/auth/oauth/callback/error'),
- 'Auth > OAuthCallbackError',
- ),
+ element: lazyElement(() => import('@/routes/auth/oauth/callback/error')),
path: 'oauth/callback/error',
},
],
element: (
<AuthShell>
- <Outlet />
+ <Suspense fallback={<Loading debugId="AuthRoutes" />}>
+ <Outlet />
+ </Suspense>
</AuthShell>
),
errorElement: <AuthErrorBoundary />,