Skip to content

Commit

Permalink
added auth
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonwcfan committed Aug 7, 2024
1 parent a9f381c commit be363d8
Show file tree
Hide file tree
Showing 8 changed files with 384 additions and 151 deletions.
6 changes: 5 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@
},
"dependencies": {
"@subframe/core": "1.119.0",
"@supabase/auth-ui-react": "^0.4.7",
"@supabase/auth-ui-shared": "^0.1.8",
"@supabase/supabase-js": "^2.45.1",
"@xyflow/react": "^12.0.4",
"classnames": "2.3.2",
"next": "14.2.5",
"react": "^18",
"react-dom": "^18"
"react-dom": "^18",
"uuid": "^10.0.0"
},
"devDependencies": {
"@types/node": "22.1.0",
Expand Down
69 changes: 53 additions & 16 deletions frontend/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,66 @@
import { Inter } from "next/font/google";
import "./globals.css";
import {ReactFlowProvider} from "@xyflow/react"
import React from "react";
import React, { useEffect } from "react";
import { useAuth } from "@/hooks/useAuth";
import { Auth } from "@supabase/auth-ui-react";
import { ThemeSupa } from "@supabase/auth-ui-shared";

const inter = Inter({ subsets: ["latin"] });

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
export default function RootLayout({ children }: Readonly<{ children: React.ReactNode }>) {
const { useLocalStorage, UserStateProvider, supabase } = useAuth();
const [session, setSession] = useLocalStorage("session", null);

useEffect(() => {
supabase.auth.getSession().then(({ data: { session } }: any) => {
setSession(session);
});

// const {
// data: { subscription }
// } = supabase.auth.onAuthStateChange((_event: any, session: any) => {
// setSession(session);
// });

// return () => subscription.unsubscribe();
}, []);

const renderAuth = () => {
return (
<div className="min-h-screen bg-gray-100 flex items-center justify-center">
<div className="bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4 w-full max-w-md">
<Auth
supabaseClient={supabase}
providers={["google"]}
appearance={{ theme: ThemeSupa }}
redirectTo={"http://localhost:3000/workflow/123"}
/>
</div>
</div>
);
};

const renderApp = () => {
return (
<UserStateProvider session={session}>
<ReactFlowProvider>
{children}
</ReactFlowProvider>
</UserStateProvider>
);
}

return (
<html lang="en">
<head>
<head>
<link rel="preconnect" href="https://fonts.googleapis.com"/>
<link rel="preconnect" href="https://fonts.gstatic.com" crossOrigin="anonymous"/>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&display=swap" rel="stylesheet"/>
</head>
<link rel="preconnect" href="https://fonts.googleapis.com"/>
<link rel="preconnect" href="https://fonts.gstatic.com" crossOrigin="anonymous"/>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&display=swap" rel="stylesheet"/>
</head>
<ReactFlowProvider>
<body className={inter.className}>
{children}
</body>
</ReactFlowProvider>
<body>
{session ? renderApp() : renderAuth()}
</body>
</html>
);
}
124 changes: 0 additions & 124 deletions frontend/src/context/UserStateContext.tsx

This file was deleted.

Loading

0 comments on commit be363d8

Please sign in to comment.