Skip to content

Commit 9a36db4

Browse files
committed
fix: disable automatic auth revalidation on auth pages
Prevents unnecessary `/api/v1/auth/me` requests on login, setup, and password reset pages. fix #738
1 parent f4fe166 commit 9a36db4

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/hooks/useUser.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { UserType } from '@server/constants/user';
22
import type { PermissionCheckOptions } from '@server/lib/permissions';
33
import { hasPermission, Permission } from '@server/lib/permissions';
44
import type { NotificationAgentKey } from '@server/lib/settings';
5+
import { useRouter } from 'next/router';
56
import type { MutatorCallback } from 'swr';
67
import useSWR from 'swr';
78

@@ -56,13 +57,19 @@ export const useUser = ({
5657
id,
5758
initialData,
5859
}: { id?: number; initialData?: User } = {}): UserHookResponse => {
60+
const router = useRouter();
61+
const isAuthPage = /^\/(login|setup|resetpassword)/.test(router.pathname);
62+
5963
const {
6064
data,
6165
error,
6266
mutate: revalidate,
6367
} = useSWR<User>(id ? `/api/v1/user/${id}` : `/api/v1/auth/me`, {
6468
fallbackData: initialData,
6569
refreshInterval: 30000,
70+
revalidateOnFocus: !isAuthPage,
71+
revalidateOnMount: !isAuthPage,
72+
revalidateOnReconnect: !isAuthPage,
6673
errorRetryInterval: 30000,
6774
shouldRetryOnError: false,
6875
});

0 commit comments

Comments
 (0)