mirror of
https://github.com/makeplane/plane.git
synced 2026-02-15 03:09:29 -06: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:
@@ -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={{
|
||||
|
||||
Reference in New Issue
Block a user