mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
fix: user public authentication workflow updates (#1207)
* auth integration fixes * auth integration fixes * auth integration fixes * auth integration fixes * dev: update user api to return fallback workspace and improve the structure of the response * dev: fix the issue keyerror and move onboarding logic to serializer method field * dev: use-user-auth hook imlemented for route access validation and build issues resolved effected by user payload * fix: global theme color fix * style: new onboarding ui , fix: use-user-auth hook implemented * fix: command palette, project invite modal and issue detail page mutation type fix * fix: onboarding redirection fix * dev: build isuue resolved * fix: use user auth hook fix * fix: sign in toast alert fix, sign out redirection fix and user theme error fix * fix: user response fix * fix: unAuthorizedStatus logic updated * dev: Implemented SEO in app.tsx * dev: User public auth workflow updates. --------- Co-authored-by: sriram veeraghanta <veeraghanta.sriram@gmail.com> Co-authored-by: pablohashescobar <nikhilschacko@gmail.com> Co-authored-by: anmolsinghbhatia <anmolsinghbhatia@caravel.tech>
This commit is contained in:
parent
77e05a3599
commit
7eae6b4c9e
@ -17,7 +17,7 @@ type EmailPasswordFormValues = {
|
||||
medium?: string;
|
||||
};
|
||||
|
||||
export const EmailPasswordForm = ({ onSuccess }: any) => {
|
||||
export const EmailPasswordForm = ({ handleSignIn }: any) => {
|
||||
const { setToastAlert } = useToast();
|
||||
const {
|
||||
register,
|
||||
@ -38,7 +38,7 @@ export const EmailPasswordForm = ({ onSuccess }: any) => {
|
||||
authenticationService
|
||||
.emailLogin(formData)
|
||||
.then((response) => {
|
||||
onSuccess(response);
|
||||
if (handleSignIn) handleSignIn(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
|
@ -13,6 +13,8 @@ import type { IWorkspace, ICurrentUserResponse } from "types";
|
||||
|
||||
const useUserAuth = (routeAuth: "sign-in" | "onboarding" | "admin" | null = "admin") => {
|
||||
const router = useRouter();
|
||||
const { next_url } = router.query as { next_url: string };
|
||||
|
||||
const [isRouteAccess, setIsRouteAccess] = useState(true);
|
||||
|
||||
const {
|
||||
@ -48,8 +50,6 @@ const useUserAuth = (routeAuth: "sign-in" | "onboarding" | "admin" | null = "adm
|
||||
};
|
||||
|
||||
const handleUserRouteAuthentication = async () => {
|
||||
console.log("user", user);
|
||||
|
||||
if (user && user.is_active) {
|
||||
if (routeAuth === "sign-in") {
|
||||
if (user.is_onboarded) handleWorkSpaceRedirection();
|
||||
@ -82,8 +82,10 @@ const useUserAuth = (routeAuth: "sign-in" | "onboarding" | "admin" | null = "adm
|
||||
|
||||
if (!isLoading) {
|
||||
setIsRouteAccess(() => true);
|
||||
if (user) handleUserRouteAuthentication();
|
||||
else {
|
||||
if (user) {
|
||||
if (next_url) router.push(next_url);
|
||||
else handleUserRouteAuthentication();
|
||||
} else {
|
||||
if (routeAuth === "sign-in") {
|
||||
setIsRouteAccess(() => false);
|
||||
return;
|
||||
@ -93,7 +95,7 @@ const useUserAuth = (routeAuth: "sign-in" | "onboarding" | "admin" | null = "adm
|
||||
}
|
||||
}
|
||||
}
|
||||
}, [user, isLoading, routeAuth, router]);
|
||||
}, [user, isLoading, routeAuth, router, next_url]);
|
||||
|
||||
return {
|
||||
isLoading: isRouteAccess,
|
||||
|
@ -1,4 +1,7 @@
|
||||
// next imports
|
||||
import Head from "next/head";
|
||||
import dynamic from "next/dynamic";
|
||||
import Router from "next/router";
|
||||
|
||||
// themes
|
||||
import { ThemeProvider } from "next-themes";
|
||||
@ -10,9 +13,6 @@ import "styles/command-pallette.css";
|
||||
import "styles/nprogress.css";
|
||||
import "styles/react-datepicker.css";
|
||||
|
||||
import Router from "next/router";
|
||||
import Head from "next/head";
|
||||
|
||||
// nprogress
|
||||
import NProgress from "nprogress";
|
||||
|
||||
@ -49,6 +49,21 @@ function MyApp({ Component, pageProps }: AppProps) {
|
||||
<ToastContextProvider>
|
||||
<ThemeContextProvider>
|
||||
<CrispWithNoSSR />
|
||||
<Head>
|
||||
<title>{SITE_TITLE}</title>
|
||||
<meta property="og:site_name" content={SITE_NAME} />
|
||||
<meta property="og:title" content={SITE_TITLE} />
|
||||
<meta property="og:url" content={SITE_URL} />
|
||||
<meta name="description" content={SITE_DESCRIPTION} />
|
||||
<meta property="og:description" content={SITE_DESCRIPTION} />
|
||||
<meta name="keywords" content={SITE_KEYWORDS} />
|
||||
<meta name="twitter:site" content={`@${TWITTER_USER_NAME}`} />
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="/favicon/apple-touch-icon.png" />
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="/favicon/favicon-32x32.png" />
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="/favicon/favicon-16x16.png" />
|
||||
<link rel="manifest" href="/site.webmanifest.json" />
|
||||
<link rel="shortcut icon" href="/favicon/favicon.ico" />
|
||||
</Head>
|
||||
<Component {...pageProps} />
|
||||
</ThemeContextProvider>
|
||||
</ToastContextProvider>
|
||||
|
@ -73,6 +73,21 @@ const HomePage: NextPage = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleEmailPasswordSignIn = async (response: any) => {
|
||||
try {
|
||||
if (response) {
|
||||
mutateUser();
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
setToastAlert({
|
||||
title: "Error signing in!",
|
||||
type: "error",
|
||||
message: "Something went wrong. Please try again later or contact the support team.",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<DefaultLayout>
|
||||
{isLoading ? (
|
||||
@ -101,7 +116,7 @@ const HomePage: NextPage = () => {
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<EmailPasswordForm />
|
||||
<EmailPasswordForm handleSignIn={handleEmailPasswordSignIn} />
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
@ -41,8 +41,6 @@ const Onboarding: NextPage = () => {
|
||||
|
||||
const { user } = useUserAuth("onboarding");
|
||||
|
||||
console.log("user", user);
|
||||
|
||||
return (
|
||||
<UserAuthorizationLayout>
|
||||
<DefaultLayout>
|
||||
|
@ -10,7 +10,7 @@ axios.interceptors.response.use(
|
||||
Cookies.remove("refreshToken", { path: "/" });
|
||||
Cookies.remove("accessToken", { path: "/" });
|
||||
if (window.location.pathname != "/")
|
||||
window.location.href = "/?next_url=window.location.pathname";
|
||||
window.location.href = `/?next_url=${window.location.pathname}`;
|
||||
}
|
||||
return Promise.reject(error);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user