gpt-engineer-app[bot] commited on
Commit
b95b772
·
1 Parent(s): 85fb69b
Files changed (3) hide show
  1. src/hooks/use-auth.ts +24 -0
  2. src/routeTree.gen.ts +30 -3
  3. src/routes/auth.tsx +124 -0
src/hooks/use-auth.ts ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useEffect, useState } from "react";
2
+ import { supabase } from "@/integrations/supabase/client";
3
+ import type { Session, User } from "@supabase/supabase-js";
4
+
5
+ export function useAuth() {
6
+ const [session, setSession] = useState<Session | null>(null);
7
+ const [user, setUser] = useState<User | null>(null);
8
+ const [loading, setLoading] = useState(true);
9
+
10
+ useEffect(() => {
11
+ const { data: sub } = supabase.auth.onAuthStateChange((_e, s) => {
12
+ setSession(s);
13
+ setUser(s?.user ?? null);
14
+ });
15
+ supabase.auth.getSession().then(({ data }) => {
16
+ setSession(data.session);
17
+ setUser(data.session?.user ?? null);
18
+ setLoading(false);
19
+ });
20
+ return () => sub.subscription.unsubscribe();
21
+ }, []);
22
+
23
+ return { session, user, loading };
24
+ }
src/routeTree.gen.ts CHANGED
@@ -9,8 +9,14 @@
9
  // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.
10
 
11
  import { Route as rootRouteImport } from './routes/__root'
 
12
  import { Route as IndexRouteImport } from './routes/index'
13
 
 
 
 
 
 
14
  const IndexRoute = IndexRouteImport.update({
15
  id: '/',
16
  path: '/',
@@ -19,28 +25,39 @@ const IndexRoute = IndexRouteImport.update({
19
 
20
  export interface FileRoutesByFullPath {
21
  '/': typeof IndexRoute
 
22
  }
23
  export interface FileRoutesByTo {
24
  '/': typeof IndexRoute
 
25
  }
26
  export interface FileRoutesById {
27
  __root__: typeof rootRouteImport
28
  '/': typeof IndexRoute
 
29
  }
30
  export interface FileRouteTypes {
31
  fileRoutesByFullPath: FileRoutesByFullPath
32
- fullPaths: '/'
33
  fileRoutesByTo: FileRoutesByTo
34
- to: '/'
35
- id: '__root__' | '/'
36
  fileRoutesById: FileRoutesById
37
  }
38
  export interface RootRouteChildren {
39
  IndexRoute: typeof IndexRoute
 
40
  }
41
 
42
  declare module '@tanstack/react-router' {
43
  interface FileRoutesByPath {
 
 
 
 
 
 
 
44
  '/': {
45
  id: '/'
46
  path: '/'
@@ -53,7 +70,17 @@ declare module '@tanstack/react-router' {
53
 
54
  const rootRouteChildren: RootRouteChildren = {
55
  IndexRoute: IndexRoute,
 
56
  }
57
  export const routeTree = rootRouteImport
58
  ._addFileChildren(rootRouteChildren)
59
  ._addFileTypes<FileRouteTypes>()
 
 
 
 
 
 
 
 
 
 
9
  // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.
10
 
11
  import { Route as rootRouteImport } from './routes/__root'
12
+ import { Route as AuthRouteImport } from './routes/auth'
13
  import { Route as IndexRouteImport } from './routes/index'
14
 
15
+ const AuthRoute = AuthRouteImport.update({
16
+ id: '/auth',
17
+ path: '/auth',
18
+ getParentRoute: () => rootRouteImport,
19
+ } as any)
20
  const IndexRoute = IndexRouteImport.update({
21
  id: '/',
22
  path: '/',
 
25
 
26
  export interface FileRoutesByFullPath {
27
  '/': typeof IndexRoute
28
+ '/auth': typeof AuthRoute
29
  }
30
  export interface FileRoutesByTo {
31
  '/': typeof IndexRoute
32
+ '/auth': typeof AuthRoute
33
  }
34
  export interface FileRoutesById {
35
  __root__: typeof rootRouteImport
36
  '/': typeof IndexRoute
37
+ '/auth': typeof AuthRoute
38
  }
39
  export interface FileRouteTypes {
40
  fileRoutesByFullPath: FileRoutesByFullPath
41
+ fullPaths: '/' | '/auth'
42
  fileRoutesByTo: FileRoutesByTo
43
+ to: '/' | '/auth'
44
+ id: '__root__' | '/' | '/auth'
45
  fileRoutesById: FileRoutesById
46
  }
47
  export interface RootRouteChildren {
48
  IndexRoute: typeof IndexRoute
49
+ AuthRoute: typeof AuthRoute
50
  }
51
 
52
  declare module '@tanstack/react-router' {
53
  interface FileRoutesByPath {
54
+ '/auth': {
55
+ id: '/auth'
56
+ path: '/auth'
57
+ fullPath: '/auth'
58
+ preLoaderRoute: typeof AuthRouteImport
59
+ parentRoute: typeof rootRouteImport
60
+ }
61
  '/': {
62
  id: '/'
63
  path: '/'
 
70
 
71
  const rootRouteChildren: RootRouteChildren = {
72
  IndexRoute: IndexRoute,
73
+ AuthRoute: AuthRoute,
74
  }
75
  export const routeTree = rootRouteImport
76
  ._addFileChildren(rootRouteChildren)
77
  ._addFileTypes<FileRouteTypes>()
78
+
79
+ import type { getRouter } from './router.tsx'
80
+ import type { createStart } from '@tanstack/react-start'
81
+ declare module '@tanstack/react-start' {
82
+ interface Register {
83
+ ssr: true
84
+ router: Awaited<ReturnType<typeof getRouter>>
85
+ }
86
+ }
src/routes/auth.tsx ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { createFileRoute, Link, useNavigate } from "@tanstack/react-router";
2
+ import { useEffect, useState } from "react";
3
+ import { supabase } from "@/integrations/supabase/client";
4
+ import { Button } from "@/components/ui/button";
5
+ import { Input } from "@/components/ui/input";
6
+ import { Label } from "@/components/ui/label";
7
+ import { toast } from "sonner";
8
+ import { Radar, ShieldAlert } from "lucide-react";
9
+
10
+ export const Route = createFileRoute("/auth")({
11
+ component: AuthPage,
12
+ });
13
+
14
+ function AuthPage() {
15
+ const navigate = useNavigate();
16
+ const [mode, setMode] = useState<"login" | "signup">("login");
17
+ const [email, setEmail] = useState("");
18
+ const [password, setPassword] = useState("");
19
+ const [name, setName] = useState("");
20
+ const [loading, setLoading] = useState(false);
21
+
22
+ useEffect(() => {
23
+ supabase.auth.getSession().then(({ data }) => {
24
+ if (data.session) navigate({ to: "/dashboard" });
25
+ });
26
+ }, [navigate]);
27
+
28
+ const submit = async (e: React.FormEvent) => {
29
+ e.preventDefault();
30
+ setLoading(true);
31
+ try {
32
+ if (mode === "signup") {
33
+ const { error } = await supabase.auth.signUp({
34
+ email, password,
35
+ options: {
36
+ emailRedirectTo: `${window.location.origin}/dashboard`,
37
+ data: { display_name: name || email.split("@")[0] },
38
+ },
39
+ });
40
+ if (error) throw error;
41
+ toast.success("Account created. Signing you in…");
42
+ } else {
43
+ const { error } = await supabase.auth.signInWithPassword({ email, password });
44
+ if (error) throw error;
45
+ }
46
+ navigate({ to: "/dashboard" });
47
+ } catch (err: any) {
48
+ toast.error(err.message || "Authentication failed");
49
+ } finally {
50
+ setLoading(false);
51
+ }
52
+ };
53
+
54
+ return (
55
+ <div className="min-h-screen grid lg:grid-cols-2">
56
+ <div className="hidden lg:flex flex-col justify-between p-12 bg-[var(--gradient-brand)] relative overflow-hidden">
57
+ <div className="absolute inset-0 opacity-30" style={{ backgroundImage: "radial-gradient(circle at 30% 30%, oklch(0.78 0.14 200 / 0.4), transparent 50%)" }} />
58
+ <div className="relative">
59
+ <div className="flex items-center gap-3">
60
+ <div className="h-10 w-10 rounded-lg bg-primary text-primary-foreground flex items-center justify-center">
61
+ <Radar className="h-5 w-5" />
62
+ </div>
63
+ <span className="text-xl font-bold tracking-tight">AVISYS</span>
64
+ </div>
65
+ </div>
66
+ <div className="relative space-y-6 max-w-md">
67
+ <ShieldAlert className="h-10 w-10 text-primary" />
68
+ <h1 className="text-4xl font-bold leading-tight">
69
+ Multi-agent safety analysis for autonomous fleets.
70
+ </h1>
71
+ <p className="text-muted-foreground text-lg">
72
+ Upload incident reports, telemetry transcripts, or sensor logs. AVISYS extracts events, identifies root causes, flags compliance risks, and drafts coaching plans — in seconds.
73
+ </p>
74
+ <div className="flex gap-2 pt-4 font-mono text-xs text-muted-foreground">
75
+ <span className="px-2 py-1 rounded bg-surface border border-border">EVENT</span>
76
+ <span className="px-2 py-1 rounded bg-surface border border-border">SAFETY</span>
77
+ <span className="px-2 py-1 rounded bg-surface border border-border">RISK</span>
78
+ <span className="px-2 py-1 rounded bg-surface border border-border">DOC</span>
79
+ </div>
80
+ </div>
81
+ </div>
82
+
83
+ <div className="flex items-center justify-center p-6 lg:p-12">
84
+ <form onSubmit={submit} className="w-full max-w-md space-y-6">
85
+ <div>
86
+ <h2 className="text-3xl font-bold">{mode === "login" ? "Sign in" : "Create account"}</h2>
87
+ <p className="text-sm text-muted-foreground mt-1">
88
+ {mode === "login" ? "Welcome back, operator." : "Get access to the safety console."}
89
+ </p>
90
+ </div>
91
+
92
+ {mode === "signup" && (
93
+ <div className="space-y-2">
94
+ <Label htmlFor="name">Display name</Label>
95
+ <Input id="name" value={name} onChange={(e) => setName(e.target.value)} placeholder="Jordan Reyes" />
96
+ </div>
97
+ )}
98
+ <div className="space-y-2">
99
+ <Label htmlFor="email">Email</Label>
100
+ <Input id="email" type="email" required value={email} onChange={(e) => setEmail(e.target.value)} placeholder="ops@fleet.io" />
101
+ </div>
102
+ <div className="space-y-2">
103
+ <Label htmlFor="password">Password</Label>
104
+ <Input id="password" type="password" required minLength={6} value={password} onChange={(e) => setPassword(e.target.value)} />
105
+ </div>
106
+
107
+ <Button type="submit" disabled={loading} className="w-full bg-primary text-primary-foreground hover:bg-primary/90 font-semibold">
108
+ {loading ? "…" : mode === "login" ? "Sign in" : "Create account"}
109
+ </Button>
110
+
111
+ <p className="text-sm text-muted-foreground text-center">
112
+ {mode === "login" ? "No account?" : "Have an account?"}{" "}
113
+ <button type="button" className="text-primary font-medium hover:underline" onClick={() => setMode(mode === "login" ? "signup" : "login")}>
114
+ {mode === "login" ? "Sign up" : "Sign in"}
115
+ </button>
116
+ </p>
117
+ <p className="text-xs text-center text-muted-foreground">
118
+ <Link to="/" className="hover:text-foreground">← Back home</Link>
119
+ </p>
120
+ </form>
121
+ </div>
122
+ </div>
123
+ );
124
+ }