Skip to content

Commit

Permalink
fix(data): ⚡ change error revalidation time
Browse files Browse the repository at this point in the history
  • Loading branch information
Nudelsuppe42 committed Oct 22, 2023
1 parent fdb66bb commit 2a0dfe5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
28 changes: 16 additions & 12 deletions src/components/SWRSetup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,23 @@ export default function SWRSetup({ content }: any) {
<SWRConfig
value={{
refreshInterval: 0,
fetcher: (resource: any, init: any) =>
!resource.includes('/undefined') &&
fetch(process.env.NEXT_PUBLIC_API_URL + resource, {
headers: {
'Access-Control-Allow-Origin': '*',
Authorization: 'Bearer ' + session.data?.accessToken,
...init?.headers,
},
...init,
})
.then((res) => res.json())
.then((d) => d),
fetcher: (resource: any, init: any) => {
if (!resource.includes('/undefined')) {
return fetch(process.env.NEXT_PUBLIC_API_URL + resource, {
headers: {
'Access-Control-Allow-Origin': '*',
Authorization: 'Bearer ' + session.data?.accessToken,
...init?.headers,
},
...init,
})
.then((res) => res.json())
.then((d) => d);
}
},
shouldRetryOnError: true,
errorRetryInterval: 2,
errorRetryCount: 2,
revalidateIfStale: false,
revalidateOnFocus: false,
revalidateOnReconnect: false,
Expand Down
11 changes: 2 additions & 9 deletions src/hooks/useUser.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
import { useEffect, useState } from 'react';
import useSWR, { mutate } from 'swr';

import minimatch from 'minimatch';
import { useSession } from 'next-auth/react';

export const useUser = () => {
const { data } = useSWR('/account');
const { data, isLoading } = useSWR('/account');
const session = useSession();
const [loading, setLoading] = useState(true);
useEffect(() => {
if (data && session.status != 'loading') setLoading(false);
}, [data, session]);

const user = {
user: data,
token: session.data?.accessToken,
isLoading: loading,
isLoading: session.status === 'loading' && isLoading,
refresh: () => mutate('/account'),
hasPermission: (p: string, buildteam?: string) => {
return user.hasPermissions([p], buildteam);
Expand All @@ -26,7 +20,6 @@ export const useUser = () => {
if (permissions.filter((p: any) => (buildteam ? p.buildTeamId === buildteam : true)).find((p: any) => ps.includes(p.permission))) return true;
return false;
},
reload: () => mutate('/account'),
};
return user;
};

0 comments on commit 2a0dfe5

Please sign in to comment.