forked from github/plane
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:
parent
53df658b60
commit
5869c91d70
@ -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={{
|
||||
|
Loading…
Reference in New Issue
Block a user