Skip to content

Commit

Permalink
Add login logic scaffolding
Browse files Browse the repository at this point in the history
  • Loading branch information
devleejb committed Jan 16, 2024
1 parent 896e7bd commit d8d2eb9
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 0 deletions.
2 changes: 2 additions & 0 deletions frontend/.env.development
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
VITE_YORKIE_API_ADDR='https://api.yorkie.dev'
VITE_YORKIE_API_KEY=''
VITE_SUPABASE_URL=''
VITE_SUPABASE_ANON=''
29 changes: 29 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@mui/material": "^5.15.3",
"@react-hook/window-size": "^3.1.1",
"@reduxjs/toolkit": "^2.0.1",
"@supabase/auth-ui-react": "^0.4.7",
"@supabase/supabase-js": "^2.39.3",
"@swc/helpers": "^0.5.3",
"@uiw/codemirror-theme-xcode": "^4.21.21",
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ import { useEffect, useMemo } from "react";
import { selectConfig } from "./store/configSlice";
import { createClient } from "@supabase/supabase-js";
import { setClient } from "./store/supabaseSlice";
import Index from "./pages/Index";

const router = createBrowserRouter([
{
path: "/",
element: <EditorLayout />,
children: [
{
path: "/",
element: <Index />,
},
{
path: ":documentId",
element: <EditorIndex />,
Expand Down
40 changes: 40 additions & 0 deletions frontend/src/pages/Index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { useEffect, useState } from "react";
import { useSelector } from "react-redux";
import { selectSupabase } from "../store/supabaseSlice";
import { Session } from "@supabase/supabase-js";
import { Auth } from "@supabase/auth-ui-react";
import { ThemeSupa } from "@supabase/auth-ui-shared";
import { Box } from "@mui/material";

function Index() {
const supabaseStore = useSelector(selectSupabase);
const [session, setSession] = useState<Session | null>(null);

useEffect(() => {
if (!supabaseStore.client) return;

supabaseStore.client.auth.getSession().then(({ data: { session } }) => {
setSession(session);
});

const {
data: { subscription },
} = supabaseStore.client.auth.onAuthStateChange((_event, session) => {
setSession(session);
});

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

if (!session && supabaseStore.client) {
return (
<Box p={4}>
<Auth supabaseClient={supabaseStore.client} appearance={{ theme: ThemeSupa }} />
</Box>
);
} else {
return <div>Logged in!</div>;
}
}

export default Index;

0 comments on commit d8d2eb9

Please sign in to comment.