From 7cbbae9fefb60c8b348bb5090008bd7f50f1a978 Mon Sep 17 00:00:00 2001 From: giancarlo Date: Sun, 21 Apr 2024 19:53:16 +0800 Subject: [PATCH] Remove Suspense from root-providers and refine route checks The Suspense wrapper was removed from root-providers.tsx to simplify code. For the Privacy Path Checking, a property was added to 'AuthRedirectListener' to allow customization of 'privatePathPrefixes', and the prefixes list was moved to the top. Also, explicit constant assertions were added in 'create-i18n-settings.ts' to ensure the types correctness. --- apps/web/components/root-providers.tsx | 36 +++++++++---------- packages/i18n/src/create-i18n-settings.ts | 6 ++-- .../src/components/auth-change-listener.tsx | 15 ++++---- 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/apps/web/components/root-providers.tsx b/apps/web/components/root-providers.tsx index a899c415f..4b01ee6d5 100644 --- a/apps/web/components/root-providers.tsx +++ b/apps/web/components/root-providers.tsx @@ -1,7 +1,5 @@ 'use client'; -import { Suspense } from 'react'; - import dynamic from 'next/dynamic'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; @@ -46,25 +44,23 @@ export function RootProviders({ return ( - - - - + + + - - - {children} - - - - - + + + {children} + + + + ); diff --git a/packages/i18n/src/create-i18n-settings.ts b/packages/i18n/src/create-i18n-settings.ts index 92d3a634a..5afdc0b67 100644 --- a/packages/i18n/src/create-i18n-settings.ts +++ b/packages/i18n/src/create-i18n-settings.ts @@ -21,9 +21,9 @@ export function createI18nSettings({ fallbackLng: languages[0], detection: undefined, lng, - load: 'languageOnly', - preload: false, - lowerCaseLng: true, + load: 'languageOnly' as const, + preload: false as const, + lowerCaseLng: true as const, fallbackNS: ns, ns, react: { diff --git a/packages/supabase/src/components/auth-change-listener.tsx b/packages/supabase/src/components/auth-change-listener.tsx index 8e8eb8067..6a7e7fe90 100644 --- a/packages/supabase/src/components/auth-change-listener.tsx +++ b/packages/supabase/src/components/auth-change-listener.tsx @@ -12,11 +12,15 @@ import { useUserSession, } from '../hooks/use-user-session'; +const PRIVATE_PATH_PREFIXES = ['/home', '/admin', '/join', '/update-password']; + function AuthRedirectListener({ children, + privatePathPrefixes = PRIVATE_PATH_PREFIXES, appHomePath, }: React.PropsWithChildren<{ appHomePath: string; + privatePathPrefixes?: string[]; }>) { const client = useSupabase(); const pathName = usePathname(); @@ -30,7 +34,8 @@ function AuthRedirectListener({ const listener = client.auth.onAuthStateChange((_, user) => { // log user out if user is falsy // and if the current path is a private route - const shouldRedirectUser = !user && isPrivateRoute(pathName); + const shouldRedirectUser = + !user && isPrivateRoute(pathName, privatePathPrefixes); if (shouldRedirectUser) { // send user away when signed out @@ -86,11 +91,7 @@ export function AuthChangeListener({ /** * Determines if a given path is a private route. - * - * @param {string} path - The path to check. */ -function isPrivateRoute(path: string) { - const prefixes = ['/home', '/admin', '/join', '/update-password']; - - return prefixes.some((prefix) => path.startsWith(prefix)); +function isPrivateRoute(path: string, privatePathPrefixes: string[]) { + return privatePathPrefixes.some((prefix) => path.startsWith(prefix)); }