Skip to content

Commit b3a02f0

Browse files
committed
Merge branch 'dev'
2 parents 439a5b8 + 7833d40 commit b3a02f0

6 files changed

Lines changed: 168 additions & 163 deletions

File tree

src/Account.tsx

Lines changed: 0 additions & 131 deletions
This file was deleted.

src/App.tsx

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { Component, createEffect, createSignal } from "solid-js";
1+
import { Component } from "solid-js";
22
import { Router, Route } from "@solidjs/router";
33
import { Toaster } from "solid-toast";
44

5-
import Login from "./components/Login";
5+
import { AuthLayout } from "./components/auth-layout";
6+
import Login from "./components/login";
67
import Dashboard from "./pages/dashboard";
78
import Profile from "./pages/profile";
89
import About from "./pages/about";
@@ -15,11 +16,36 @@ const App: Component = () => {
1516
return (
1617
<>
1718
<Router base={base}>
19+
{/* Public routes */}
1820
<Route path="/login" component={Login} />
1921
<Route path="/" component={Login} />
20-
<Route path="/dashboard" component={Dashboard} />
21-
<Route path="/profile" component={Profile} />
22-
<Route path="/about" component={About} />
22+
23+
{/* Protected routes with AuthLayout */}
24+
<Route
25+
path="/dashboard"
26+
component={() => (
27+
<AuthLayout>
28+
<Dashboard />
29+
</AuthLayout>
30+
)}
31+
/>
32+
<Route
33+
path="/profile"
34+
component={() => (
35+
<AuthLayout>
36+
<Profile />
37+
</AuthLayout>
38+
)}
39+
/>
40+
<Route
41+
path="/about"
42+
component={() => (
43+
<AuthLayout>
44+
<About />
45+
</AuthLayout>
46+
)}
47+
/>
48+
{/* 404 route */}
2349
<Route path="/**404" component={NotFound} />
2450
</Router>
2551
<Toaster />

src/components/Login.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ const Login = () => {
2424
const navigate = useNavigate();
2525
const supaAuth = useSupabaseAuth();
2626

27-
// createEffect(() => {
28-
// supaAuth.getSession().then(({ data: { session } }) => {
29-
// if (session) {
30-
// navigate("/dashboard");
31-
// }
32-
// });
33-
// });
27+
createEffect(() => {
28+
supaAuth.getSession().then(({ data: { session } }) => {
29+
if (session) {
30+
navigate("/dashboard");
31+
}
32+
});
33+
});
3434

3535
const handleSendToken = async (e: SubmitEvent) => {
3636
e.preventDefault();
@@ -134,12 +134,11 @@ const Login = () => {
134134
</p>
135135
<p class="truncate font-medium text-center">{email()}</p>
136136
<TextField class="grid gap-2">
137-
{/* <TextFieldLabel>Verification Code</TextFieldLabel> */}
138137
<TextFieldInput
139138
id="token"
140139
class="text-center text-lg tracking-wide"
141140
type="text"
142-
placeholder="Enter verification code"
141+
placeholder="Verification code"
143142
value={token()}
144143
onChange={(e) => setToken(e.currentTarget.value)}
145144
maxLength={6}

src/components/auth-layout.tsx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { Show, JSX, createEffect, createSignal } from "solid-js";
2+
import { A, useNavigate } from "@solidjs/router";
3+
import { useSupabase } from "solid-supabase";
4+
5+
import { UserNav } from "./user-nav";
6+
import { SiteNav } from "./site-nav";
7+
8+
interface AuthLayoutProps {
9+
children: JSX.Element;
10+
}
11+
12+
export function AuthLayout(props: AuthLayoutProps) {
13+
const [isAuthenticated, setIsAuthenticated] = createSignal(false);
14+
const navigate = useNavigate();
15+
const supabase = useSupabase();
16+
17+
createEffect(async () => {
18+
const { data } = await supabase.auth.getSession();
19+
20+
if (!data.session) {
21+
navigate("/login", { replace: true });
22+
return;
23+
}
24+
25+
setIsAuthenticated(true);
26+
});
27+
28+
return (
29+
<Show when={isAuthenticated()}>
30+
<div class="min-h-screen flex flex-col">
31+
<header class="border-b sticky top-0 z-30 bg-background">
32+
<div class="container flex h-16 items-center justify-between py-4">
33+
<div class="flex gap-6 items-center">
34+
<A
35+
href="/dashboard"
36+
class="font-semibold flex items-center gap-2">
37+
Supa Solid User
38+
</A>
39+
<SiteNav />
40+
</div>
41+
<UserNav />
42+
</div>
43+
</header>
44+
<main class="flex-1">{props.children}</main>
45+
</div>
46+
</Show>
47+
);
48+
}

src/components/site-nav.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { A } from "@solidjs/router";
2+
3+
interface NavLinkProps {
4+
href: string;
5+
children: any;
6+
active?: boolean;
7+
}
8+
9+
const NavLink = (props: NavLinkProps) => {
10+
return (
11+
<A
12+
href={props.href}
13+
class="text-sm font-medium transition-colors hover:text-primary"
14+
activeClass="text-foreground font-semibold"
15+
inactiveClass="text-muted-foreground">
16+
{props.children}
17+
</A>
18+
);
19+
};
20+
21+
export function SiteNav() {
22+
return (
23+
<nav class="flex items-center space-x-6">
24+
<NavLink href="/dashboard">Dashboard</NavLink>
25+
<NavLink href="/profile">Profile</NavLink>
26+
<NavLink href="/about">About</NavLink>
27+
</nav>
28+
);
29+
}

0 commit comments

Comments
 (0)