Fixed React Query provider. Removed getSession and replaced with getUser to make Supabase happy. Fixed Stepper's responsiveness.
This commit is contained in:
@@ -5,7 +5,11 @@ import { SiteHeader } from '~/(marketing)/_components/site-header';
|
|||||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||||
|
|
||||||
async function SiteLayout(props: React.PropsWithChildren) {
|
async function SiteLayout(props: React.PropsWithChildren) {
|
||||||
const user = await getUser();
|
const client = getSupabaseServerComponentClient();
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: { user },
|
||||||
|
} = await client.auth.getUser();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={'flex min-h-[100vh] flex-col'}>
|
<div className={'flex min-h-[100vh] flex-col'}>
|
||||||
@@ -19,18 +23,3 @@ async function SiteLayout(props: React.PropsWithChildren) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default withI18n(SiteLayout);
|
export default withI18n(SiteLayout);
|
||||||
|
|
||||||
async function getUser() {
|
|
||||||
const client = getSupabaseServerComponentClient();
|
|
||||||
|
|
||||||
// Supabase is going to be complaining about this line
|
|
||||||
// since we use getSession instead of getUser
|
|
||||||
// we don't quite care because we only need to know if the user is logged in
|
|
||||||
// to display the user menu in the header.
|
|
||||||
// There is no need to ping the server while navigating to marketing pages.
|
|
||||||
const {
|
|
||||||
data: { session },
|
|
||||||
} = await client.auth.getSession();
|
|
||||||
|
|
||||||
return session?.user;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,21 +1,23 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useState } from 'react';
|
||||||
|
|
||||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||||
|
|
||||||
// set gcTime to 0 on the server
|
|
||||||
// as we cannot invalidate the cache on the server
|
|
||||||
const isServer = typeof document === 'undefined';
|
|
||||||
const gcTime = isServer ? 0 : undefined;
|
|
||||||
const staleTime = isServer ? 0 : 60 * 1000;
|
|
||||||
|
|
||||||
const queryClient = new QueryClient({
|
|
||||||
defaultOptions: {
|
|
||||||
queries: {
|
|
||||||
gcTime,
|
|
||||||
staleTime,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export function ReactQueryProvider(props: React.PropsWithChildren) {
|
export function ReactQueryProvider(props: React.PropsWithChildren) {
|
||||||
|
const [queryClient] = useState(
|
||||||
|
() =>
|
||||||
|
new QueryClient({
|
||||||
|
defaultOptions: {
|
||||||
|
queries: {
|
||||||
|
// With SSR, we usually want to set some default staleTime
|
||||||
|
// above 0 to avoid refetching immediately on the client
|
||||||
|
staleTime: 60 * 1000,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<QueryClientProvider client={queryClient}>
|
<QueryClientProvider client={queryClient}>
|
||||||
{props.children}
|
{props.children}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { usePathname, useRouter } from 'next/navigation';
|
|||||||
import { useQueryClient } from '@tanstack/react-query';
|
import { useQueryClient } from '@tanstack/react-query';
|
||||||
|
|
||||||
import { useSupabase } from './use-supabase';
|
import { useSupabase } from './use-supabase';
|
||||||
import { useRevalidateUserSession, useUserSession } from './use-user-session';
|
import { useRevalidateUserSession } from './use-user-session';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name PRIVATE_PATH_PREFIXES
|
* @name PRIVATE_PATH_PREFIXES
|
||||||
@@ -31,9 +31,7 @@ export function useAuthChangeListener({
|
|||||||
const pathName = usePathname();
|
const pathName = usePathname();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const revalidateUserSession = useRevalidateUserSession();
|
const revalidateUserSession = useRevalidateUserSession();
|
||||||
const session = useUserSession();
|
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const accessToken = session.data?.access_token;
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// keep this running for the whole session unless the component was unmounted
|
// keep this running for the whole session unless the component was unmounted
|
||||||
@@ -56,15 +54,6 @@ export function useAuthChangeListener({
|
|||||||
|
|
||||||
return router.refresh();
|
return router.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
// revalidate user session when access token is out of sync
|
|
||||||
if (accessToken) {
|
|
||||||
const isOutOfSync = user?.access_token !== accessToken;
|
|
||||||
|
|
||||||
if (isOutOfSync) {
|
|
||||||
void router.refresh();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// destroy listener on un-mounts
|
// destroy listener on un-mounts
|
||||||
@@ -72,7 +61,6 @@ export function useAuthChangeListener({
|
|||||||
}, [
|
}, [
|
||||||
client.auth,
|
client.auth,
|
||||||
router,
|
router,
|
||||||
accessToken,
|
|
||||||
revalidateUserSession,
|
revalidateUserSession,
|
||||||
pathName,
|
pathName,
|
||||||
appHomePath,
|
appHomePath,
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ function StepDivider({
|
|||||||
complete: boolean;
|
complete: boolean;
|
||||||
}>) {
|
}>) {
|
||||||
const spanClassName = cn('font-medium text-sm min-w-max', {
|
const spanClassName = cn('font-medium text-sm min-w-max', {
|
||||||
['text-muted-foreground']: !selected,
|
['text-muted-foreground hidden sm:flex']: !selected,
|
||||||
['text-secondary-foreground']: selected || complete,
|
['text-secondary-foreground']: selected || complete,
|
||||||
['font-medium']: selected,
|
['font-medium']: selected,
|
||||||
});
|
});
|
||||||
@@ -172,7 +172,7 @@ function StepDivider({
|
|||||||
<div
|
<div
|
||||||
className={
|
className={
|
||||||
'divider h-[1px] w-full bg-gray-200 transition-colors' +
|
'divider h-[1px] w-full bg-gray-200 transition-colors' +
|
||||||
' group-last:hidden dark:bg-border'
|
' hidden group-last:hidden dark:bg-border sm:flex'
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
13767
pnpm-lock.yaml
generated
13767
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user