forked from github/plane
fix: space user validation check
This commit is contained in:
parent
b14d44049c
commit
a195f1bf7e
@ -16,7 +16,6 @@ function initializeStore(initialData = {}) {
|
|||||||
// If your page has Next.js data fetching methods that use a Mobx store, it will
|
// If your page has Next.js data fetching methods that use a Mobx store, it will
|
||||||
// get hydrated here, check `pages/ssg.js` and `pages/ssr.js` for more details
|
// get hydrated here, check `pages/ssg.js` and `pages/ssr.js` for more details
|
||||||
if (initialData) {
|
if (initialData) {
|
||||||
console.log("initialState", initialData);
|
|
||||||
singletonRootStore.hydrate(initialData);
|
singletonRootStore.hydrate(initialData);
|
||||||
}
|
}
|
||||||
// For SSG and SSR always create a new store
|
// For SSG and SSR always create a new store
|
||||||
|
20
space/app/loading.tsx
Normal file
20
space/app/loading.tsx
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
"use client";
|
||||||
|
import Image from "next/image";
|
||||||
|
import { useTheme } from "next-themes";
|
||||||
|
// assets
|
||||||
|
import LogoSpinnerDark from "@/public/images/logo-spinner-dark.gif";
|
||||||
|
import LogoSpinnerLight from "@/public/images/logo-spinner-light.gif";
|
||||||
|
|
||||||
|
export default function LogoSpinner() {
|
||||||
|
const { resolvedTheme } = useTheme();
|
||||||
|
|
||||||
|
const logoSrc = resolvedTheme === "dark" ? LogoSpinnerDark : LogoSpinnerLight;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="h-screen w-full flex min-h-[600px] justify-center items-center">
|
||||||
|
<div className="flex items-center justify-center">
|
||||||
|
<Image src={logoSrc} alt="logo" className="w-[82px] h-[82px] mr-2" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
@ -1,20 +1,27 @@
|
|||||||
|
"use client";
|
||||||
|
import { observer } from "mobx-react-lite";
|
||||||
|
import useSWR from "swr";
|
||||||
// components
|
// components
|
||||||
import { UserLoggedIn } from "@/components/accounts";
|
import { UserLoggedIn } from "@/components/accounts";
|
||||||
|
import { LogoSpinner } from "@/components/common";
|
||||||
import { AuthView } from "@/components/views";
|
import { AuthView } from "@/components/views";
|
||||||
// services
|
// hooks
|
||||||
import { UserService } from "@/services/user.service";
|
import { useUser } from "@/hooks/store";
|
||||||
|
|
||||||
const userServices = new UserService();
|
function HomePage() {
|
||||||
|
const { fetchCurrentUser, isAuthenticated, isLoading } = useUser();
|
||||||
|
|
||||||
export default async function HomePage() {
|
useSWR("CURRENT_USER", () => fetchCurrentUser(), { errorRetryCount: 0 });
|
||||||
const user = await userServices
|
|
||||||
.currentUser()
|
|
||||||
.then((user) => ({ ...user, isAuthenticated: true }))
|
|
||||||
.catch(() => ({ isAuthenticated: false }));
|
|
||||||
|
|
||||||
if (user.isAuthenticated) {
|
if (isLoading) {
|
||||||
|
return <LogoSpinner />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isAuthenticated) {
|
||||||
return <UserLoggedIn />;
|
return <UserLoggedIn />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return <AuthView />;
|
return <AuthView />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default observer(HomePage);
|
||||||
|
@ -11,6 +11,7 @@ export const UserLoggedIn = () => {
|
|||||||
const { data: user } = useUser();
|
const { data: user } = useUser();
|
||||||
|
|
||||||
if (!user) return null;
|
if (!user) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex h-screen w-screen flex-col">
|
<div className="flex h-screen w-screen flex-col">
|
||||||
<div className="relative flex w-full items-center justify-between gap-4 border-b border-custom-border-200 px-6 py-5">
|
<div className="relative flex w-full items-center justify-between gap-4 border-b border-custom-border-200 px-6 py-5">
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
export * from "./latest-feature-block";
|
export * from "./latest-feature-block";
|
||||||
export * from "./project-logo";
|
export * from "./project-logo";
|
||||||
|
export * from "./logo-spinner";
|
||||||
|
20
space/components/common/logo-spinner.tsx
Normal file
20
space/components/common/logo-spinner.tsx
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
"use client";
|
||||||
|
import Image from "next/image";
|
||||||
|
import { useTheme } from "next-themes";
|
||||||
|
// assets
|
||||||
|
import LogoSpinnerDark from "@/public/images/logo-spinner-dark.gif";
|
||||||
|
import LogoSpinnerLight from "@/public/images/logo-spinner-light.gif";
|
||||||
|
|
||||||
|
export const LogoSpinner = () => {
|
||||||
|
const { resolvedTheme } = useTheme();
|
||||||
|
|
||||||
|
const logoSrc = resolvedTheme === "dark" ? LogoSpinnerDark : LogoSpinnerLight;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="h-screen w-full flex min-h-[600px] justify-center items-center">
|
||||||
|
<div className="flex items-center justify-center">
|
||||||
|
<Image src={logoSrc} alt="logo" className="w-[82px] h-[82px] mr-2" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
@ -1,8 +1,10 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useEffect, FC } from "react";
|
import { useEffect, FC } from "react";
|
||||||
|
import { observer } from "mobx-react-lite";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useRouter, useParams, useSearchParams, usePathname } from "next/navigation";
|
import { useRouter, useParams, useSearchParams, usePathname } from "next/navigation";
|
||||||
|
import useSWR from "swr";
|
||||||
// ui
|
// ui
|
||||||
import { Avatar, Button } from "@plane/ui";
|
import { Avatar, Button } from "@plane/ui";
|
||||||
// components
|
// components
|
||||||
@ -21,7 +23,7 @@ export type NavbarControlsProps = {
|
|||||||
projectSettings: any;
|
projectSettings: any;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const NavbarControls: FC<NavbarControlsProps> = (props) => {
|
export const NavbarControls: FC<NavbarControlsProps> = observer((props) => {
|
||||||
const { workspaceSlug, projectId, projectSettings } = props;
|
const { workspaceSlug, projectId, projectSettings } = props;
|
||||||
const { views } = projectSettings;
|
const { views } = projectSettings;
|
||||||
// router
|
// router
|
||||||
@ -34,7 +36,11 @@ export const NavbarControls: FC<NavbarControlsProps> = (props) => {
|
|||||||
const { settings, activeLayout, hydrate, setActiveLayout } = useProject();
|
const { settings, activeLayout, hydrate, setActiveLayout } = useProject();
|
||||||
hydrate(projectSettings);
|
hydrate(projectSettings);
|
||||||
|
|
||||||
const { data: user } = useUser();
|
const { data: user, fetchCurrentUser } = useUser();
|
||||||
|
|
||||||
|
useSWR("CURRENT_USER", () => fetchCurrentUser(), { errorRetryCount: 2 });
|
||||||
|
|
||||||
|
console.log("user", user);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (workspaceSlug && projectId && settings) {
|
if (workspaceSlug && projectId && settings) {
|
||||||
@ -126,4 +132,4 @@ export const NavbarControls: FC<NavbarControlsProps> = (props) => {
|
|||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
});
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { FC } from "react";
|
import { FC } from "react";
|
||||||
import { observer } from "mobx-react-lite";
|
|
||||||
import { Briefcase } from "lucide-react";
|
import { Briefcase } from "lucide-react";
|
||||||
// components
|
// components
|
||||||
import { ProjectLogo } from "@/components/common";
|
import { ProjectLogo } from "@/components/common";
|
||||||
@ -13,7 +11,7 @@ type IssueNavbarProps = {
|
|||||||
projectId: string;
|
projectId: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const IssueNavbar: FC<IssueNavbarProps> = observer((props) => {
|
const IssueNavbar: FC<IssueNavbarProps> = (props) => {
|
||||||
const { projectSettings, workspaceSlug, projectId } = props;
|
const { projectSettings, workspaceSlug, projectId } = props;
|
||||||
const { project_details } = projectSettings;
|
const { project_details } = projectSettings;
|
||||||
|
|
||||||
@ -40,6 +38,6 @@ const IssueNavbar: FC<IssueNavbarProps> = observer((props) => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
});
|
};
|
||||||
|
|
||||||
export default IssueNavbar;
|
export default IssueNavbar;
|
||||||
|
@ -4,12 +4,8 @@ import { observer } from "mobx-react-lite";
|
|||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
// ui
|
// ui
|
||||||
import { useTheme } from "next-themes";
|
import { useTheme } from "next-themes";
|
||||||
import useSWR from "swr";
|
|
||||||
import { Spinner } from "@plane/ui";
|
|
||||||
// components
|
// components
|
||||||
import { AuthRoot } from "@/components/accounts";
|
import { AuthRoot } from "@/components/accounts";
|
||||||
// hooks
|
|
||||||
import { useUser } from "@/hooks/store";
|
|
||||||
// images
|
// images
|
||||||
import PlaneBackgroundPatternDark from "public/auth/background-pattern-dark.svg";
|
import PlaneBackgroundPatternDark from "public/auth/background-pattern-dark.svg";
|
||||||
import PlaneBackgroundPattern from "public/auth/background-pattern.svg";
|
import PlaneBackgroundPattern from "public/auth/background-pattern.svg";
|
||||||
@ -18,26 +14,8 @@ import BluePlaneLogoWithoutText from "public/plane-logos/blue-without-text-new.p
|
|||||||
export const AuthView = observer(() => {
|
export const AuthView = observer(() => {
|
||||||
// hooks
|
// hooks
|
||||||
const { resolvedTheme } = useTheme();
|
const { resolvedTheme } = useTheme();
|
||||||
// store
|
|
||||||
const { fetchCurrentUser, isLoading } = useUser();
|
|
||||||
|
|
||||||
// fetching user information
|
|
||||||
const { isLoading: isSWRLoading } = useSWR("CURRENT_USER_DETAILS", () => fetchCurrentUser(), {
|
|
||||||
shouldRetryOnError: false,
|
|
||||||
revalidateOnFocus: false,
|
|
||||||
revalidateIfStale: false,
|
|
||||||
revalidateOnReconnect: true,
|
|
||||||
errorRetryCount: 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
|
||||||
{isLoading || isSWRLoading ? (
|
|
||||||
<div className="relative flex h-screen w-screen items-center justify-center">
|
|
||||||
<Spinner />
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<div className="relative w-screen h-screen overflow-hidden">
|
<div className="relative w-screen h-screen overflow-hidden">
|
||||||
<div className="absolute inset-0 z-0">
|
<div className="absolute inset-0 z-0">
|
||||||
<Image
|
<Image
|
||||||
@ -58,8 +36,5 @@ export const AuthView = observer(() => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
BIN
space/public/images/logo-spinner-dark.gif
Normal file
BIN
space/public/images/logo-spinner-dark.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 36 KiB |
BIN
space/public/images/logo-spinner-light.gif
Normal file
BIN
space/public/images/logo-spinner-light.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 35 KiB |
@ -4,13 +4,13 @@ import axios, { AxiosInstance } from "axios";
|
|||||||
// import { rootStore } from "@/lib/store-context";
|
// import { rootStore } from "@/lib/store-context";
|
||||||
|
|
||||||
export abstract class APIService {
|
export abstract class APIService {
|
||||||
protected baseURL: string;
|
protected baseURL: string | undefined;
|
||||||
private axiosInstance: AxiosInstance;
|
private axiosInstance: AxiosInstance;
|
||||||
|
|
||||||
constructor(baseURL: string) {
|
constructor(baseURL: string | undefined) {
|
||||||
this.baseURL = baseURL;
|
this.baseURL = baseURL;
|
||||||
this.axiosInstance = axios.create({
|
this.axiosInstance = axios.create({
|
||||||
baseURL,
|
baseURL: baseURL || "",
|
||||||
withCredentials: true,
|
withCredentials: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ export interface IUserStore {
|
|||||||
export class UserStore implements IUserStore {
|
export class UserStore implements IUserStore {
|
||||||
// observables
|
// observables
|
||||||
isAuthenticated: boolean = false;
|
isAuthenticated: boolean = false;
|
||||||
isLoading: boolean = false;
|
isLoading: boolean = true;
|
||||||
error: TUserErrorStatus | undefined = undefined;
|
error: TUserErrorStatus | undefined = undefined;
|
||||||
data: IUser | undefined = undefined;
|
data: IUser | undefined = undefined;
|
||||||
// store observables
|
// store observables
|
||||||
|
Loading…
Reference in New Issue
Block a user