diff --git a/apps/app/components/account/email-password-form.tsx b/apps/app/components/account/email-password-form.tsx index 3527ae440..7d56d67a0 100644 --- a/apps/app/components/account/email-password-form.tsx +++ b/apps/app/components/account/email-password-form.tsx @@ -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); diff --git a/apps/app/hooks/use-user-auth.tsx b/apps/app/hooks/use-user-auth.tsx index 9dba5ce61..619a2fcdd 100644 --- a/apps/app/hooks/use-user-auth.tsx +++ b/apps/app/hooks/use-user-auth.tsx @@ -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, diff --git a/apps/app/pages/_app.tsx b/apps/app/pages/_app.tsx index 2b0c2ab6b..402736a36 100644 --- a/apps/app/pages/_app.tsx +++ b/apps/app/pages/_app.tsx @@ -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) { + + {SITE_TITLE} + + + + + + + + + + + + + diff --git a/apps/app/pages/index.tsx b/apps/app/pages/index.tsx index b032fb203..9f3ef51ba 100644 --- a/apps/app/pages/index.tsx +++ b/apps/app/pages/index.tsx @@ -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 ( {isLoading ? ( @@ -101,7 +116,7 @@ const HomePage: NextPage = () => { ) : ( <> - + )} diff --git a/apps/app/pages/onboarding.tsx b/apps/app/pages/onboarding.tsx index 9d24a7664..64b08e2f8 100644 --- a/apps/app/pages/onboarding.tsx +++ b/apps/app/pages/onboarding.tsx @@ -41,8 +41,6 @@ const Onboarding: NextPage = () => { const { user } = useUserAuth("onboarding"); - console.log("user", user); - return ( diff --git a/apps/app/services/api.service.ts b/apps/app/services/api.service.ts index 296b693aa..cf540e2b5 100644 --- a/apps/app/services/api.service.ts +++ b/apps/app/services/api.service.ts @@ -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); }