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
This commit is contained in:
Dakshesh Jain 2023-03-21 12:48:17 +05:30 committed by GitHub
parent 53df658b60
commit 5869c91d70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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<IUserContextProps>({} as IUserContextProps);
export const UserProvider = ({ children }: { children: ReactElement }) => {
const router = useRouter();
// API to fetch user information
const { data, error, mutate } = useSWR<IUser>(CURRENT_USER, () => userService.currentUser(), {
shouldRetryOnError: false,
});
if (error) {
router.push("/signin");
return null;
}
return (
<UserContext.Provider
value={{