mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
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";
|
import React, { createContext, ReactElement } from "react";
|
||||||
|
// next
|
||||||
|
import { useRouter } from "next/router";
|
||||||
// swr
|
// swr
|
||||||
import useSWR, { KeyedMutator } from "swr";
|
import useSWR, { KeyedMutator } from "swr";
|
||||||
// services
|
// services
|
||||||
@ -20,11 +22,18 @@ interface IUserContextProps {
|
|||||||
export const UserContext = createContext<IUserContextProps>({} as IUserContextProps);
|
export const UserContext = createContext<IUserContextProps>({} as IUserContextProps);
|
||||||
|
|
||||||
export const UserProvider = ({ children }: { children: ReactElement }) => {
|
export const UserProvider = ({ children }: { children: ReactElement }) => {
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
// API to fetch user information
|
// API to fetch user information
|
||||||
const { data, error, mutate } = useSWR<IUser>(CURRENT_USER, () => userService.currentUser(), {
|
const { data, error, mutate } = useSWR<IUser>(CURRENT_USER, () => userService.currentUser(), {
|
||||||
shouldRetryOnError: false,
|
shouldRetryOnError: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
router.push("/signin");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<UserContext.Provider
|
<UserContext.Provider
|
||||||
value={{
|
value={{
|
||||||
|
Loading…
Reference in New Issue
Block a user