Skip to content

✨ Innovative and open-source visualization application that transforms various data formats, such as JSON, YAML, XML and CSV into interactive graphs.

remove supabase session check from _app

AykutSarac8f60bf683b04
diff --git a/src/components/GoogleAnalytics/index.tsx b/src/components/GoogleAnalytics/index.tsx
index a627e2c7..c340d5a6 100644
--- a/src/components/GoogleAnalytics/index.tsx
+++ b/src/components/GoogleAnalytics/index.tsx
@@ -5,7 +5,7 @@ import ReactGA from "react-ga";
const isDevelopment = process.env.NODE_ENV === "development";
const GA_TRACKING_ID = process.env.NEXT_PUBLIC_GA_ID;
-ReactGA.initialize(GA_TRACKING_ID, { testMode: isDevelopment });
+ReactGA.initialize(GA_TRACKING_ID, { testMode: isDevelopment, useExistingGa: true });
const GoogleAnalytics: React.FC = () => {
if (isDevelopment) return null;
diff --git a/src/hooks/useCheckSession.ts b/src/hooks/useCheckSession.ts
new file mode 100644
index 00000000..3ae3eb33
--- /dev/null
+++ b/src/hooks/useCheckSession.ts
@@ -0,0 +1,19 @@
+import React from "react";
+import { supabase } from "src/lib/api/supabase";
+import useUser from "src/store/useUser";
+
+export const useCheckSession = () => {
+ const [hasSession, setHasSession] = React.useState(false);
+ const setSession = useUser(state => state.setSession);
+
+ React.useEffect(() => {
+ supabase.auth.getSession().then(({ data: { session } }) => {
+ if (session) {
+ setSession(session);
+ setHasSession(true);
+ } else setHasSession(false);
+ });
+ }, [setSession]);
+
+ return { hasSession };
+};
diff --git a/src/layout/Navbar/index.tsx b/src/layout/Navbar/index.tsx
index b4231f79..5541e2e7 100644
--- a/src/layout/Navbar/index.tsx
+++ b/src/layout/Navbar/index.tsx
@@ -3,7 +3,6 @@ import Link from "next/link";
import styled from "styled-components";
import { Button } from "@mantine/core";
import { FaStar } from "react-icons/fa";
-import useUser from "src/store/useUser";
import { JSONCrackLogo } from "../JsonCrackLogo";
const StyledNavbarWrapper = styled.div`
@@ -44,8 +43,6 @@ const Right = styled.div`
`;
export const Navbar = () => {
- const isAuthenticated = useUser(state => state.isAuthenticated);
-
return (
<StyledNavbarWrapper>
<StyledNavbar>
@@ -89,13 +86,11 @@ export const Navbar = () => {
>
Star us on GitHub
</Button>
- {!isAuthenticated && (
- <Link href="/sign-in" prefetch={false}>
- <Button variant="light" radius="md" className="hide-mobile">
- Sign In
- </Button>
- </Link>
- )}
+ <Link href="/sign-in" prefetch={false}>
+ <Button variant="light" radius="md" className="hide-mobile">
+ Sign In
+ </Button>
+ </Link>
<Link href="/editor" prefetch={false}>
<Button color="pink" radius="md">
Editor
diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx
index 53d82b5e..619f5941 100644
--- a/src/pages/_app.tsx
+++ b/src/pages/_app.tsx
@@ -4,13 +4,10 @@ import dynamic from "next/dynamic";
import { useRouter } from "next/router";
import { StyleSheetManager, ThemeProvider } from "styled-components";
import { MantineProvider, MantineThemeOverride } from "@mantine/core";
-import { SessionContextProvider, Session } from "@supabase/auth-helpers-react";
import { pageview } from "react-ga";
import { monaSans } from "src/constants/fonts";
import GlobalStyle from "src/constants/globalStyle";
import { lightTheme } from "src/constants/theme";
-import { supabase } from "src/lib/api/supabase";
-import useUser from "src/store/useUser";
const Toaster = dynamic(() => import("react-hot-toast").then(c => c.Toaster));
const ExternalMode = dynamic(() => import("src/layout/ExternalMode"));
@@ -24,20 +21,8 @@ const mantineTheme: MantineThemeOverride = {
primaryShade: 8,
};
-function JsonCrack({
- Component,
- pageProps,
-}: AppProps<{
- initialSession: Session;
-}>) {
+function JsonCrack({ Component, pageProps }: AppProps) {
const router = useRouter();
- const setSession = useUser(state => state.setSession);
-
- React.useEffect(() => {
- supabase.auth.getSession().then(({ data: { session } }) => {
- if (session) setSession(session);
- });
- }, [setSession]);
React.useEffect(() => {
const handleRouteChange = (url: string) => {
@@ -52,7 +37,7 @@ function JsonCrack({
}, [router.events]);
return (
- <SessionContextProvider supabaseClient={supabase}>
+ <>
<GoogleAnalytics />
<StyleSheetManager>
<ThemeProvider theme={lightTheme}>
@@ -78,7 +63,7 @@ function JsonCrack({
</MantineProvider>
</ThemeProvider>
</StyleSheetManager>
- </SessionContextProvider>
+ </>
);
}
diff --git a/src/pages/editor.tsx b/src/pages/editor.tsx
index dd525f51..b8d1670d 100644
--- a/src/pages/editor.tsx
+++ b/src/pages/editor.tsx
@@ -5,6 +5,7 @@ import { useRouter } from "next/router";
import styled from "styled-components";
import { BottomBar } from "src/containers/Editor/BottomBar";
import { Tools } from "src/containers/Editor/LiveEditor/Tools";
+import { useCheckSession } from "src/hooks/useCheckSession";
import { EditorWrapper } from "src/layout/EditorWrapper";
import { Loading } from "src/layout/Loading";
import useFile from "src/store/useFile";
@@ -29,8 +30,9 @@ export const StyledEditorWrapper = styled.div`
const EditorPage: React.FC = () => {
const { query, isReady } = useRouter();
- const checkEditorSession = useFile(state => state.checkEditorSession);
const loading = useJson(state => state.loading);
+ const checkEditorSession = useFile(state => state.checkEditorSession);
+ useCheckSession();
React.useEffect(() => {
if (isReady) checkEditorSession(query?.json);
diff --git a/src/pages/index.tsx b/src/pages/index.tsx
index 17674f2f..b243d6d9 100644
--- a/src/pages/index.tsx
+++ b/src/pages/index.tsx
@@ -202,7 +202,7 @@ const HeroSection = () => (
const StatsBanner = () => (
<StyledStatsWrapper>
- <Group spacing="xl">
+ <Group spacing="xl" style={{ flex: 1 }}>
<Stack spacing="0">
<Text fw="bolder" fz="1.6rem">
24.5K
@@ -228,7 +228,7 @@ const StatsBanner = () => (
</Text>
</Stack>
</Group>
- <Stack ml={60}>
+ <Stack ml={60} style={{ flex: 1 }}>
<Text maw={800} fz="0.9rem">
JSON Crack is an open-source project with a GPL-3 license. By subscribing to our premium
plan, you can help us continue developing and maintaining it, also enjoy the benefits.
diff --git a/src/pages/reset-password.tsx b/src/pages/reset-password.tsx
index 796993a3..dcec6c50 100644
--- a/src/pages/reset-password.tsx
+++ b/src/pages/reset-password.tsx
@@ -3,8 +3,8 @@ import Head from "next/head";
import Link from "next/link";
import { useRouter } from "next/router";
import { PaperProps, Button, Group, Paper, Stack, TextInput, Text, Anchor } from "@mantine/core";
-import { useSession } from "@supabase/auth-helpers-react";
import { toast } from "react-hot-toast";
+import { useCheckSession } from "src/hooks/useCheckSession";
import { Footer } from "src/layout/Footer";
import { JSONCrackLogo } from "src/layout/JsonCrackLogo";
import { Navbar } from "src/layout/Navbar";
@@ -65,13 +65,13 @@ export function AuthenticationForm(props: PaperProps) {
);
}
-const SignIn = () => {
+const ResetPassword = () => {
const { isReady, push } = useRouter();
- const session = useSession();
+ const { hasSession } = useCheckSession();
React.useEffect(() => {
- if (session) push("/editor");
- }, [isReady, session, push]);
+ if (hasSession) push("/editor");
+ }, [isReady, hasSession, push]);
return (
<div>
@@ -88,4 +88,4 @@ const SignIn = () => {
);
};
-export default SignIn;
+export default ResetPassword;
diff --git a/src/pages/sign-in.tsx b/src/pages/sign-in.tsx
index 11f7c8f4..23d664a3 100644
--- a/src/pages/sign-in.tsx
+++ b/src/pages/sign-in.tsx
@@ -17,9 +17,9 @@ import {
} from "@mantine/core";
import { useForm } from "@mantine/form";
import { useToggle, upperFirst } from "@mantine/hooks";
-import { useSession } from "@supabase/auth-helpers-react";
import { toast } from "react-hot-toast";
import { AiOutlineGithub, AiOutlineGoogle } from "react-icons/ai";
+import { useCheckSession } from "src/hooks/useCheckSession";
import { Footer } from "src/layout/Footer";
import { JSONCrackLogo } from "src/layout/JsonCrackLogo";
import { Navbar } from "src/layout/Navbar";
@@ -267,12 +267,12 @@ function ResetPassword(props: PaperProps) {
const SignIn = () => {
const { isReady, push, query } = useRouter();
- const session = useSession();
+ const { hasSession } = useCheckSession();
const isPasswordReset = query?.type === "recovery" && !query?.error;
React.useEffect(() => {
- if (session) push("/editor");
- }, [isReady, session, push]);
+ if (hasSession) push("/editor");
+ }, [isReady, hasSession, push]);
return (
<div>