@@ -5,7 +5,7 @@ import axios from 'axios' import * as https from 'https' import type { AppProps } from 'next/app' import { Raleway } from 'next/font/google' -import { SessionProvider } from 'next-auth/react' +import { SessionProvider, getSession } from 'next-auth/react' import { appWithTranslation } from 'next-i18next' import * as Sentry from '@sentry/browser' @@ -41,6 +41,18 @@ axios.defaults.httpsAgent = new https.Agent({ axios.defaults.validateStatus = () => true +axios.interceptors.response.use(async (response) => { + if (response.status !== 401) return response + + const session = await getSession() + + console.log(session) + + if (!session) window.location.href = '/login' + + return response +}) + const inter = Raleway({ subsets: ['latin'] }) export type NextPageWithLayout

= NextPage & { @@ -50,12 +50,7 @@ export const Layout: React.FC = ({ children, titlePage, title = tit signOut() push('/login') } - - useEffect(() => { - if (!sessionData) return - ;(!sessionData.access || sessionData.access === '' || !sessionData.user || Object.values(sessionData.user).length === 0) && logout() - }, [sessionData]) - + async function getUserData(access: string) { await dispatch(getUserBalance(access)) await dispatch(getAllInfo(access))