From 5869c91d70e79892802461a2ae121b0a39c4cb88 Mon Sep 17 00:00:00 2001 From: Dakshesh Jain <65905942+dakshesh14@users.noreply.github.com> Date: Tue, 21 Mar 2023 12:48:17 +0530 Subject: [PATCH] fix: added redirection to sign-in page if fetching user was a fail in the context (#481) * refractor: added params to fetch key * feat: create views directly from views list page fix: selected filter not showing up in multi-level dropdown, refactor: arranged imports * fix: added redirection to sign-in page if fetching user was a fail in the context --- apps/app/contexts/user.context.tsx | 9 +++++++++ 1 file changed, 9 insertions(+) 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 (