mirror of
https://github.com/fallenbagel/jellyseerr.git
synced 2025-12-23 18:29:19 -05:00
fix: disable automatic auth revalidation on auth pages (#2213)
* fix: disable automatic auth revalidation on auth pages Prevents unnecessary `/api/v1/auth/me` requests on login, setup, and password reset pages. fix #738 * fix: update regex to include resetpassword guid & add missing condition in refreshInterval
This commit is contained in:
@@ -2,6 +2,7 @@ import { UserType } from '@server/constants/user';
|
|||||||
import type { PermissionCheckOptions } from '@server/lib/permissions';
|
import type { PermissionCheckOptions } from '@server/lib/permissions';
|
||||||
import { hasPermission, Permission } from '@server/lib/permissions';
|
import { hasPermission, Permission } from '@server/lib/permissions';
|
||||||
import type { NotificationAgentKey } from '@server/lib/settings';
|
import type { NotificationAgentKey } from '@server/lib/settings';
|
||||||
|
import { useRouter } from 'next/router';
|
||||||
import type { MutatorCallback } from 'swr';
|
import type { MutatorCallback } from 'swr';
|
||||||
import useSWR from 'swr';
|
import useSWR from 'swr';
|
||||||
|
|
||||||
@@ -56,13 +57,21 @@ export const useUser = ({
|
|||||||
id,
|
id,
|
||||||
initialData,
|
initialData,
|
||||||
}: { id?: number; initialData?: User } = {}): UserHookResponse => {
|
}: { id?: number; initialData?: User } = {}): UserHookResponse => {
|
||||||
|
const router = useRouter();
|
||||||
|
const isAuthPage = /^\/(login|setup|resetpassword(?:\/|$))/.test(
|
||||||
|
router.pathname
|
||||||
|
);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data,
|
data,
|
||||||
error,
|
error,
|
||||||
mutate: revalidate,
|
mutate: revalidate,
|
||||||
} = useSWR<User>(id ? `/api/v1/user/${id}` : `/api/v1/auth/me`, {
|
} = useSWR<User>(id ? `/api/v1/user/${id}` : `/api/v1/auth/me`, {
|
||||||
fallbackData: initialData,
|
fallbackData: initialData,
|
||||||
refreshInterval: 30000,
|
refreshInterval: !isAuthPage ? 30000 : 0,
|
||||||
|
revalidateOnFocus: !isAuthPage,
|
||||||
|
revalidateOnMount: !isAuthPage,
|
||||||
|
revalidateOnReconnect: !isAuthPage,
|
||||||
errorRetryInterval: 30000,
|
errorRetryInterval: 30000,
|
||||||
shouldRetryOnError: false,
|
shouldRetryOnError: false,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user