diff --git a/apps/app/contexts/user.context.tsx b/apps/app/contexts/user.context.tsx index d68e7c618..1b8b7bca6 100644 --- a/apps/app/contexts/user.context.tsx +++ b/apps/app/contexts/user.context.tsx @@ -1,4 +1,6 @@ import React, { createContext, ReactElement } from "react"; +// next +import { useRouter } from "next/router"; // swr import useSWR, { KeyedMutator } from "swr"; // services @@ -20,11 +22,18 @@ interface IUserContextProps { export const UserContext = createContext({} as IUserContextProps); export const UserProvider = ({ children }: { children: ReactElement }) => { + const router = useRouter(); + // API to fetch user information const { data, error, mutate } = useSWR(CURRENT_USER, () => userService.currentUser(), { shouldRetryOnError: false, }); + if (error) { + router.push("/signin"); + return null; + } + return (