Refactor authentication listener to be a hook

The previous authentication listener component was transformed into a `useAuthChangeListener` hook. All relevant functionality was preserved in this transition. The purpose of this change was to improve flexibility and code reusability by enabling the auth listener to be integrated in various parts of the application as needed. The old component was also removed from the exported packages in the `package.json`.
This commit is contained in:
giancarlo
2024-04-22 19:46:45 +08:00
parent a074e1ec3b
commit 8c5b0496da
4 changed files with 32 additions and 39 deletions

View File

@@ -9,7 +9,7 @@ import { ThemeProvider } from 'next-themes';
import { CaptchaProvider } from '@kit/auth/captcha/client';
import { I18nProvider } from '@kit/i18n/provider';
import { MonitoringProvider } from '@kit/monitoring/components';
import { AuthChangeListener } from '@kit/supabase/components/auth-change-listener';
import { useAuthChangeListener } from '@kit/supabase/hooks/use-auth-change-listener';
import appConfig from '~/config/app.config';
import authConfig from '~/config/auth.config';
@@ -50,7 +50,7 @@ export function RootProviders({
<CaptchaProvider>
<CaptchaTokenSetter siteKey={captchaSiteKey} />
<AuthChangeListener appHomePath={pathsConfig.app.home}>
<AuthProvider>
<ThemeProvider
attribute="class"
enableSystem
@@ -60,7 +60,7 @@ export function RootProviders({
>
{children}
</ThemeProvider>
</AuthChangeListener>
</AuthProvider>
</CaptchaProvider>
</I18nProvider>
</ReactQueryStreamedHydration>
@@ -68,3 +68,12 @@ export function RootProviders({
</MonitoringProvider>
);
}
// we place this below React Query since it uses the QueryClient
function AuthProvider(props: React.PropsWithChildren) {
useAuthChangeListener({
appHomePath: pathsConfig.app.home,
});
return props.children;
}