AWS SES preview
This commit is contained in:
8
.claude/settings.local.json
Normal file
8
.claude/settings.local.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"permissions": {
|
||||||
|
"allow": [
|
||||||
|
"WebFetch(domain:github.com)",
|
||||||
|
"Bash(find . -type f \\\\\\(-name *login* -o -name *signup* -o -name *auth* -o -name *email* -o -name *profile* \\\\\\))"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
160
App.tsx
160
App.tsx
@@ -1,31 +1,76 @@
|
|||||||
import { useState } from "react";
|
import { useState, useEffect } from 'react';
|
||||||
import { Dashboard } from "./components/Dashboard";
|
import { Dashboard } from './components/Dashboard';
|
||||||
import { Inventory } from "./components/Inventory";
|
import { Inventory } from './components/Inventory';
|
||||||
import { ProtocolChecker } from "./components/ProtocolChecker";
|
import { ProtocolChecker } from './components/ProtocolChecker';
|
||||||
import { useSession, signIn, signOut } from "./lib/auth-client";
|
import { Onboarding } from './components/Onboarding';
|
||||||
import { Button } from "./components/ui/button";
|
import { LoginForm } from './components/auth/LoginForm';
|
||||||
import { Card, CardContent } from "./components/ui/card";
|
import { SignUpForm } from './components/auth/SignUpForm';
|
||||||
import {
|
import { EmailVerification } from './components/auth/EmailVerification';
|
||||||
LayoutDashboard,
|
import { ForgotPassword } from './components/auth/ForgotPassword';
|
||||||
Package,
|
import { ResetPassword } from './components/auth/ResetPassword';
|
||||||
FileCheck,
|
import { useSession, signOut } from './lib/auth-client';
|
||||||
LogOut,
|
import { LayoutDashboard, Package, FileCheck, LogOut } from 'lucide-react';
|
||||||
} from "lucide-react";
|
|
||||||
const logo = "/logo.png";
|
|
||||||
|
|
||||||
type Tab = "dashboard" | "inventory" | "protocol";
|
const logo = '/logo.png';
|
||||||
|
|
||||||
|
type AppView =
|
||||||
|
| 'loading'
|
||||||
|
| 'login'
|
||||||
|
| 'signup'
|
||||||
|
| 'verify-email'
|
||||||
|
| 'forgot-password'
|
||||||
|
| 'reset-password'
|
||||||
|
| 'onboarding'
|
||||||
|
| 'app';
|
||||||
|
|
||||||
|
type Tab = 'dashboard' | 'inventory' | 'protocol';
|
||||||
|
|
||||||
|
function isResetPasswordRoute() {
|
||||||
|
return (
|
||||||
|
window.location.pathname === '/reset-password' &&
|
||||||
|
Boolean(new URLSearchParams(window.location.search).get('token'))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
const { data: session, isPending } = useSession();
|
const { data: session, isPending } = useSession();
|
||||||
const [activeTab, setActiveTab] = useState<Tab>("dashboard");
|
const [view, setView] = useState<AppView>(
|
||||||
|
isResetPasswordRoute() ? 'reset-password' : 'loading'
|
||||||
|
);
|
||||||
|
const [activeTab, setActiveTab] = useState<Tab>('dashboard');
|
||||||
|
|
||||||
const navItems = [
|
useEffect(() => {
|
||||||
{ id: "dashboard" as Tab, label: "Dashboard", icon: LayoutDashboard },
|
if (view === 'reset-password') return;
|
||||||
{ id: "inventory" as Tab, label: "Inventory", icon: Package },
|
if (isPending) return;
|
||||||
{ id: "protocol" as Tab, label: "Protocol Checker", icon: FileCheck },
|
|
||||||
];
|
|
||||||
|
|
||||||
if (isPending) {
|
if (!session) {
|
||||||
|
setView('login');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!session.user.emailVerified) {
|
||||||
|
setView('verify-email');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if lab profile exists
|
||||||
|
fetch('/api/profile', { credentials: 'include' }).then(r => {
|
||||||
|
setView(r.ok ? 'app' : 'onboarding');
|
||||||
|
});
|
||||||
|
}, [session, isPending, view]);
|
||||||
|
|
||||||
|
if (view === 'reset-password') {
|
||||||
|
return (
|
||||||
|
<ResetPassword
|
||||||
|
onSuccess={() => {
|
||||||
|
window.history.replaceState({}, '', '/');
|
||||||
|
setView('login');
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (view === 'loading') {
|
||||||
return (
|
return (
|
||||||
<div className="flex h-screen items-center justify-center bg-secondary">
|
<div className="flex h-screen items-center justify-center bg-secondary">
|
||||||
<img src={logo} alt="LabWise" className="h-12 opacity-50 animate-pulse" />
|
<img src={logo} alt="LabWise" className="h-12 opacity-50 animate-pulse" />
|
||||||
@@ -34,45 +79,45 @@ export default function App() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!session) {
|
if (!session) {
|
||||||
|
if (view === 'signup')
|
||||||
|
return (
|
||||||
|
<SignUpForm
|
||||||
|
onLogin={() => setView('login')}
|
||||||
|
onVerify={() => setView('verify-email')}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
if (view === 'forgot-password')
|
||||||
|
return <ForgotPassword onBack={() => setView('login')} />;
|
||||||
return (
|
return (
|
||||||
<div className="flex h-screen items-center justify-center bg-secondary">
|
<LoginForm
|
||||||
<Card className="w-full max-w-sm">
|
onSignUp={() => setView('signup')}
|
||||||
<CardContent className="p-8 space-y-6">
|
onForgotPassword={() => setView('forgot-password')}
|
||||||
<div className="flex justify-center">
|
/>
|
||||||
<img src={logo} alt="LabWise" className="h-12" />
|
|
||||||
</div>
|
|
||||||
<p className="text-center text-muted-foreground text-sm">
|
|
||||||
Sign in to access your lab inventory and protocols.
|
|
||||||
</p>
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
className="w-full flex items-center gap-3"
|
|
||||||
onClick={() => signIn.social({ provider: "google", callbackURL: window.location.origin })}
|
|
||||||
>
|
|
||||||
<svg viewBox="0 0 24 24" className="h-4 w-4" xmlns="http://www.w3.org/2000/svg">
|
|
||||||
<path d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z" fill="#4285F4"/>
|
|
||||||
<path d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z" fill="#34A853"/>
|
|
||||||
<path d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l3.66-2.84z" fill="#FBBC05"/>
|
|
||||||
<path d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z" fill="#EA4335"/>
|
|
||||||
</svg>
|
|
||||||
Sign in with Google
|
|
||||||
</Button>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (view === 'verify-email')
|
||||||
|
return <EmailVerification email={session.user.email} />;
|
||||||
|
|
||||||
|
if (view === 'onboarding')
|
||||||
|
return <Onboarding onComplete={() => setView('app')} />;
|
||||||
|
|
||||||
|
if (view !== 'app') return null;
|
||||||
|
|
||||||
|
const navItems = [
|
||||||
|
{ id: 'dashboard' as Tab, label: 'Dashboard', icon: LayoutDashboard },
|
||||||
|
{ id: 'inventory' as Tab, label: 'Inventory', icon: Package },
|
||||||
|
{ id: 'protocol' as Tab, label: 'Protocol Checker', icon: FileCheck },
|
||||||
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex h-screen bg-secondary">
|
<div className="flex h-screen bg-secondary">
|
||||||
{/* Sidebar */}
|
|
||||||
<aside className="w-64 bg-card border-r border-border flex flex-col">
|
<aside className="w-64 bg-card border-r border-border flex flex-col">
|
||||||
<div className="p-6 border-b border-border flex items-center justify-center">
|
<div className="p-6 border-b border-border flex items-center justify-center">
|
||||||
<img src={logo} alt="labwise" className="h-15" />
|
<img src={logo} alt="labwise" className="h-15" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<nav className="flex-1 p-4">
|
<nav className="flex-1 p-4">
|
||||||
{navItems.map((item) => {
|
{navItems.map(item => {
|
||||||
const Icon = item.icon;
|
const Icon = item.icon;
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
@@ -80,8 +125,8 @@ export default function App() {
|
|||||||
onClick={() => setActiveTab(item.id)}
|
onClick={() => setActiveTab(item.id)}
|
||||||
className={`w-full flex items-center gap-3 px-4 py-3 rounded-lg mb-2 transition-colors ${
|
className={`w-full flex items-center gap-3 px-4 py-3 rounded-lg mb-2 transition-colors ${
|
||||||
activeTab === item.id
|
activeTab === item.id
|
||||||
? "bg-accent text-primary"
|
? 'bg-accent text-primary'
|
||||||
: "text-muted-foreground hover:bg-muted"
|
: 'text-muted-foreground hover:bg-muted'
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<Icon className="w-5 h-5" />
|
<Icon className="w-5 h-5" />
|
||||||
@@ -90,7 +135,6 @@ export default function App() {
|
|||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div className="p-4 border-t border-border">
|
<div className="p-4 border-t border-border">
|
||||||
<div className="text-xs text-muted-foreground mb-2 truncate px-1">
|
<div className="text-xs text-muted-foreground mb-2 truncate px-1">
|
||||||
{session.user.email}
|
{session.user.email}
|
||||||
@@ -104,13 +148,11 @@ export default function App() {
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
|
|
||||||
{/* Main Content */}
|
|
||||||
<main className="flex-1 overflow-auto">
|
<main className="flex-1 overflow-auto">
|
||||||
{activeTab === "dashboard" && <Dashboard setActiveTab={setActiveTab} />}
|
{activeTab === 'dashboard' && <Dashboard setActiveTab={setActiveTab} />}
|
||||||
{activeTab === "inventory" && <Inventory />}
|
{activeTab === 'inventory' && <Inventory />}
|
||||||
{activeTab === "protocol" && <ProtocolChecker />}
|
{activeTab === 'protocol' && <ProtocolChecker />}
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
118
components/Onboarding.tsx
Normal file
118
components/Onboarding.tsx
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
import { useState } from 'react';
|
||||||
|
import { Button } from './ui/button';
|
||||||
|
import { Card, CardContent } from './ui/card';
|
||||||
|
import { Input } from './ui/input';
|
||||||
|
import { Label } from './ui/label';
|
||||||
|
import { useSession } from '../lib/auth-client';
|
||||||
|
|
||||||
|
const logo = '/logo.png';
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
onComplete: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Onboarding({ onComplete }: Props) {
|
||||||
|
const { data: session } = useSession();
|
||||||
|
const [piFirstName, setPiFirstName] = useState('');
|
||||||
|
const [bldgCode, setBldgCode] = useState('');
|
||||||
|
const [lab, setLab] = useState('');
|
||||||
|
const [contact, setContact] = useState('');
|
||||||
|
const [error, setError] = useState('');
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
async function handleSubmit(e: React.FormEvent) {
|
||||||
|
e.preventDefault();
|
||||||
|
setError('');
|
||||||
|
setLoading(true);
|
||||||
|
const res = await fetch('/api/profile', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
credentials: 'include',
|
||||||
|
body: JSON.stringify({
|
||||||
|
pi_first_name: piFirstName,
|
||||||
|
bldg_code: bldgCode,
|
||||||
|
lab,
|
||||||
|
contact: contact || undefined,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
setLoading(false);
|
||||||
|
if (res.ok) {
|
||||||
|
onComplete();
|
||||||
|
} else {
|
||||||
|
const data = await res.json();
|
||||||
|
setError(data.error || 'Failed to save profile');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex h-screen items-center justify-center bg-secondary">
|
||||||
|
<Card className="w-full max-w-sm">
|
||||||
|
<CardContent className="p-8 space-y-6">
|
||||||
|
<div className="flex justify-center">
|
||||||
|
<img src={logo} alt="LabWise" className="h-12" />
|
||||||
|
</div>
|
||||||
|
<div className="space-y-1">
|
||||||
|
<h2 className="font-semibold text-lg">
|
||||||
|
Welcome{session?.user.name ? `, ${session.user.name.split(' ')[0]}` : ''}!
|
||||||
|
</h2>
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
Set up your lab details. These will be used as defaults when adding inventory.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form onSubmit={handleSubmit} className="space-y-4">
|
||||||
|
<div className="space-y-1">
|
||||||
|
<Label htmlFor="pi">PI first name</Label>
|
||||||
|
<Input
|
||||||
|
id="pi"
|
||||||
|
type="text"
|
||||||
|
value={piFirstName}
|
||||||
|
onChange={e => setPiFirstName(e.target.value)}
|
||||||
|
required
|
||||||
|
placeholder="e.g. Smith"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-1">
|
||||||
|
<Label htmlFor="bldg">Building code</Label>
|
||||||
|
<Input
|
||||||
|
id="bldg"
|
||||||
|
type="text"
|
||||||
|
value={bldgCode}
|
||||||
|
onChange={e => setBldgCode(e.target.value)}
|
||||||
|
required
|
||||||
|
placeholder="e.g. EER"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-1">
|
||||||
|
<Label htmlFor="lab">Lab</Label>
|
||||||
|
<Input
|
||||||
|
id="lab"
|
||||||
|
type="text"
|
||||||
|
value={lab}
|
||||||
|
onChange={e => setLab(e.target.value)}
|
||||||
|
required
|
||||||
|
placeholder="e.g. 3.822"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-1">
|
||||||
|
<Label htmlFor="contact">
|
||||||
|
Contact <span className="text-muted-foreground font-normal">(optional)</span>
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id="contact"
|
||||||
|
type="text"
|
||||||
|
value={contact}
|
||||||
|
onChange={e => setContact(e.target.value)}
|
||||||
|
placeholder="Phone or email"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{error && <p className="text-sm text-red-600">{error}</p>}
|
||||||
|
<Button type="submit" className="w-full" disabled={loading}>
|
||||||
|
{loading ? 'Saving…' : 'Get started'}
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
73
components/auth/EmailVerification.tsx
Normal file
73
components/auth/EmailVerification.tsx
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
import { useState } from 'react';
|
||||||
|
import { Button } from '../ui/button';
|
||||||
|
import { Card, CardContent } from '../ui/card';
|
||||||
|
import { sendVerificationEmail, signOut } from '../../lib/auth-client';
|
||||||
|
import { Mail } from 'lucide-react';
|
||||||
|
|
||||||
|
const logo = '/logo.png';
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
email: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function EmailVerification({ email }: Props) {
|
||||||
|
const [resent, setResent] = useState(false);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
async function handleResend() {
|
||||||
|
setLoading(true);
|
||||||
|
await sendVerificationEmail({
|
||||||
|
email,
|
||||||
|
callbackURL: window.location.origin,
|
||||||
|
});
|
||||||
|
setLoading(false);
|
||||||
|
setResent(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleCheckStatus() {
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex h-screen items-center justify-center bg-secondary">
|
||||||
|
<Card className="w-full max-w-sm">
|
||||||
|
<CardContent className="p-8 space-y-6 text-center">
|
||||||
|
<div className="flex justify-center">
|
||||||
|
<img src={logo} alt="LabWise" className="h-12" />
|
||||||
|
</div>
|
||||||
|
<div className="flex justify-center">
|
||||||
|
<div className="rounded-full bg-accent p-4">
|
||||||
|
<Mail className="h-8 w-8 text-primary" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-2">
|
||||||
|
<h2 className="font-semibold text-lg">Check your email</h2>
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
We sent a verification link to <span className="font-medium text-foreground">{email}</span>.
|
||||||
|
Click the link to activate your account.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Button className="w-full" onClick={handleCheckStatus}>
|
||||||
|
I've verified — continue
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
className="w-full"
|
||||||
|
onClick={handleResend}
|
||||||
|
disabled={loading || resent}
|
||||||
|
>
|
||||||
|
{resent ? 'Email sent!' : loading ? 'Sending…' : 'Resend email'}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
onClick={() => signOut()}
|
||||||
|
className="text-xs text-muted-foreground hover:text-foreground transition-colors"
|
||||||
|
>
|
||||||
|
Use a different account
|
||||||
|
</button>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
93
components/auth/ForgotPassword.tsx
Normal file
93
components/auth/ForgotPassword.tsx
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
import { useState } from 'react';
|
||||||
|
import { Button } from '../ui/button';
|
||||||
|
import { Card, CardContent } from '../ui/card';
|
||||||
|
import { Input } from '../ui/input';
|
||||||
|
import { Label } from '../ui/label';
|
||||||
|
import { forgetPassword } from '../../lib/auth-client';
|
||||||
|
import { ArrowLeft } from 'lucide-react';
|
||||||
|
|
||||||
|
const logo = '/logo.png';
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
onBack: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ForgotPassword({ onBack }: Props) {
|
||||||
|
const [email, setEmail] = useState('');
|
||||||
|
const [sent, setSent] = useState(false);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [error, setError] = useState('');
|
||||||
|
|
||||||
|
async function handleSubmit(e: React.FormEvent) {
|
||||||
|
e.preventDefault();
|
||||||
|
setError('');
|
||||||
|
setLoading(true);
|
||||||
|
const res = await forgetPassword({
|
||||||
|
email,
|
||||||
|
redirectTo: `${window.location.origin}/reset-password`,
|
||||||
|
});
|
||||||
|
setLoading(false);
|
||||||
|
if (res.error) {
|
||||||
|
setError(res.error.message || 'Something went wrong');
|
||||||
|
} else {
|
||||||
|
setSent(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex h-screen items-center justify-center bg-secondary">
|
||||||
|
<Card className="w-full max-w-sm">
|
||||||
|
<CardContent className="p-8 space-y-6">
|
||||||
|
<div className="flex justify-center">
|
||||||
|
<img src={logo} alt="LabWise" className="h-12" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{sent ? (
|
||||||
|
<div className="space-y-4 text-center">
|
||||||
|
<h2 className="font-semibold text-lg">Check your email</h2>
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
If an account exists for <span className="font-medium text-foreground">{email}</span>,
|
||||||
|
we've sent a password reset link.
|
||||||
|
</p>
|
||||||
|
<Button variant="outline" className="w-full" onClick={onBack}>
|
||||||
|
Back to sign in
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<div className="space-y-1">
|
||||||
|
<h2 className="font-semibold text-lg">Forgot password?</h2>
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
Enter your email and we'll send you a reset link.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<form onSubmit={handleSubmit} className="space-y-4">
|
||||||
|
<div className="space-y-1">
|
||||||
|
<Label htmlFor="email">Email</Label>
|
||||||
|
<Input
|
||||||
|
id="email"
|
||||||
|
type="email"
|
||||||
|
value={email}
|
||||||
|
onChange={e => setEmail(e.target.value)}
|
||||||
|
required
|
||||||
|
autoComplete="email"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{error && <p className="text-sm text-red-600">{error}</p>}
|
||||||
|
<Button type="submit" className="w-full" disabled={loading}>
|
||||||
|
{loading ? 'Sending…' : 'Send reset link'}
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
<button
|
||||||
|
onClick={onBack}
|
||||||
|
className="flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground transition-colors"
|
||||||
|
>
|
||||||
|
<ArrowLeft className="h-3 w-3" /> Back to sign in
|
||||||
|
</button>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
261
components/auth/LoginForm.tsx
Normal file
261
components/auth/LoginForm.tsx
Normal file
@@ -0,0 +1,261 @@
|
|||||||
|
import { useRef, useState } from 'react';
|
||||||
|
import { Button } from '../ui/button';
|
||||||
|
import { Card, CardContent } from '../ui/card';
|
||||||
|
import { Input } from '../ui/input';
|
||||||
|
import { Label } from '../ui/label';
|
||||||
|
import { signIn } from '../../lib/auth-client';
|
||||||
|
import {
|
||||||
|
Package,
|
||||||
|
FileCheck,
|
||||||
|
MessageSquare,
|
||||||
|
Camera,
|
||||||
|
AlertTriangle,
|
||||||
|
ChevronDown,
|
||||||
|
} from 'lucide-react';
|
||||||
|
|
||||||
|
const logo = '/logo.png';
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
onSignUp: () => void;
|
||||||
|
onForgotPassword: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const features = [
|
||||||
|
{
|
||||||
|
icon: Package,
|
||||||
|
title: 'Smart Chemical Inventory',
|
||||||
|
description:
|
||||||
|
'Track every chemical in your lab with detailed records — storage locations, CAS numbers, container counts, and expiration dates. Get instant alerts before stock runs low or chemicals expire.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: FileCheck,
|
||||||
|
title: 'AI Protocol Checker',
|
||||||
|
description:
|
||||||
|
'Paste or upload any lab protocol and receive instant AI-powered safety feedback with citations to OSHA standards. Catch PPE gaps, ventilation requirements, and hazard oversights before they become incidents.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: MessageSquare,
|
||||||
|
title: 'Lab Safety Assistant',
|
||||||
|
description:
|
||||||
|
'Ask anything about chemical handling, disposal, compatibility, or regulatory compliance. Get sourced answers drawn from OSHA, EPA, and lab safety literature — available the moment you need them.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: Camera,
|
||||||
|
title: 'Photo Label Scanning',
|
||||||
|
description:
|
||||||
|
'Point your camera at any chemical label and LabWise auto-fills the inventory entry for you. Reduce manual entry errors and get new chemicals logged in seconds.',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export function LoginForm({ onSignUp, onForgotPassword }: Props) {
|
||||||
|
const [email, setEmail] = useState('');
|
||||||
|
const [password, setPassword] = useState('');
|
||||||
|
const [error, setError] = useState('');
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const aboutRef = useRef<HTMLElement>(null);
|
||||||
|
const heroRef = useRef<HTMLElement>(null);
|
||||||
|
|
||||||
|
async function handleSubmit(e: React.FormEvent) {
|
||||||
|
e.preventDefault();
|
||||||
|
setError('');
|
||||||
|
setLoading(true);
|
||||||
|
const res = await signIn.email({
|
||||||
|
email,
|
||||||
|
password,
|
||||||
|
callbackURL: window.location.origin,
|
||||||
|
});
|
||||||
|
setLoading(false);
|
||||||
|
if (res.error) {
|
||||||
|
setError(res.error.message || 'Invalid email or password');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleGoogle() {
|
||||||
|
await signIn.social({ provider: 'google', callbackURL: window.location.origin });
|
||||||
|
}
|
||||||
|
|
||||||
|
function scrollToAbout() {
|
||||||
|
aboutRef.current?.scrollIntoView({ behavior: 'smooth' });
|
||||||
|
}
|
||||||
|
|
||||||
|
function scrollToLogin() {
|
||||||
|
heroRef.current?.scrollIntoView({ behavior: 'smooth' });
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="min-h-screen bg-secondary">
|
||||||
|
{/* Sticky Navbar */}
|
||||||
|
<nav className="sticky top-0 z-50 bg-card border-b border-border">
|
||||||
|
<div className="max-w-6xl mx-auto px-6 h-14 flex items-center justify-between">
|
||||||
|
<img src={logo} alt="LabWise" className="h-7" />
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Button variant="ghost" size="sm" onClick={scrollToAbout}>
|
||||||
|
About
|
||||||
|
</Button>
|
||||||
|
<Button variant="outline" size="sm" onClick={scrollToLogin}>
|
||||||
|
Login
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
{/* Hero — login card */}
|
||||||
|
<section
|
||||||
|
ref={heroRef}
|
||||||
|
className="min-h-[calc(100vh-3.5rem)] flex flex-col items-center justify-center px-4 py-16"
|
||||||
|
>
|
||||||
|
<div className="text-center mb-8">
|
||||||
|
<p className="text-muted-foreground text-sm tracking-wide uppercase font-medium">
|
||||||
|
AI-powered lab management
|
||||||
|
</p>
|
||||||
|
<h1 className="text-3xl font-bold text-foreground mt-1">
|
||||||
|
Your lab, under control.
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Card className="w-full max-w-sm">
|
||||||
|
<CardContent className="p-8 space-y-6">
|
||||||
|
<div className="flex justify-center">
|
||||||
|
<img src={logo} alt="LabWise" className="h-12" />
|
||||||
|
</div>
|
||||||
|
<p className="text-center text-muted-foreground text-sm">
|
||||||
|
Sign in to access your lab inventory and protocols.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<form onSubmit={handleSubmit} className="space-y-4">
|
||||||
|
<div className="space-y-1">
|
||||||
|
<Label htmlFor="email">Email</Label>
|
||||||
|
<Input
|
||||||
|
id="email"
|
||||||
|
type="email"
|
||||||
|
value={email}
|
||||||
|
onChange={e => setEmail(e.target.value)}
|
||||||
|
required
|
||||||
|
autoComplete="email"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-1">
|
||||||
|
<Label htmlFor="password">Password</Label>
|
||||||
|
<Input
|
||||||
|
id="password"
|
||||||
|
type="password"
|
||||||
|
value={password}
|
||||||
|
onChange={e => setPassword(e.target.value)}
|
||||||
|
required
|
||||||
|
autoComplete="current-password"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{error && <p className="text-sm text-red-600">{error}</p>}
|
||||||
|
<Button type="submit" className="w-full" disabled={loading}>
|
||||||
|
{loading ? 'Signing in…' : 'Sign in'}
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<div className="flex-1 border-t border-border" />
|
||||||
|
<span className="text-xs text-muted-foreground">or</span>
|
||||||
|
<div className="flex-1 border-t border-border" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
className="w-full flex items-center gap-3"
|
||||||
|
onClick={handleGoogle}
|
||||||
|
>
|
||||||
|
<svg viewBox="0 0 24 24" className="h-4 w-4" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z" fill="#4285F4"/>
|
||||||
|
<path d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z" fill="#34A853"/>
|
||||||
|
<path d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l3.66-2.84z" fill="#FBBC05"/>
|
||||||
|
<path d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z" fill="#EA4335"/>
|
||||||
|
</svg>
|
||||||
|
Sign in with Google
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<div className="flex justify-between text-sm">
|
||||||
|
<button
|
||||||
|
onClick={onForgotPassword}
|
||||||
|
className="text-muted-foreground hover:text-foreground transition-colors"
|
||||||
|
>
|
||||||
|
Forgot password?
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={onSignUp}
|
||||||
|
className="text-primary hover:underline font-medium"
|
||||||
|
>
|
||||||
|
Create account
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{/* Scroll hint */}
|
||||||
|
<button
|
||||||
|
onClick={scrollToAbout}
|
||||||
|
className="mt-12 flex flex-col items-center gap-1 text-muted-foreground hover:text-foreground transition-colors group"
|
||||||
|
>
|
||||||
|
<span className="text-xs tracking-wide">Learn more</span>
|
||||||
|
<ChevronDown className="h-4 w-4 animate-bounce group-hover:text-primary" />
|
||||||
|
</button>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
{/* About Section */}
|
||||||
|
<section ref={aboutRef} id="about" className="bg-card border-t border-border">
|
||||||
|
<div className="max-w-5xl mx-auto px-6 py-20">
|
||||||
|
{/* Intro */}
|
||||||
|
<div className="text-center mb-16">
|
||||||
|
<div className="inline-flex items-center gap-2 bg-accent text-primary text-xs font-medium px-3 py-1 rounded-full mb-4">
|
||||||
|
<AlertTriangle className="h-3 w-3" />
|
||||||
|
Built for research labs
|
||||||
|
</div>
|
||||||
|
<h2 className="text-3xl font-bold text-foreground mb-4">
|
||||||
|
Lab management, made easy.
|
||||||
|
</h2>
|
||||||
|
<p className="text-muted-foreground max-w-2xl mx-auto leading-relaxed">
|
||||||
|
LabWise brings together chemical inventory tracking, AI-powered protocol review, and real-time
|
||||||
|
safety alerts in one place — so your team spends less time on paperwork and more time on research.
|
||||||
|
Whether you're managing a single lab or multiple rooms across a department, LabWise keeps
|
||||||
|
everything organized, compliant, and accessible.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Feature grid */}
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-6 mb-16">
|
||||||
|
{features.map(({ icon: Icon, title, description }) => (
|
||||||
|
<div
|
||||||
|
key={title}
|
||||||
|
className="flex gap-4 p-6 rounded-xl border border-border bg-secondary hover:shadow-md transition-shadow"
|
||||||
|
>
|
||||||
|
<div className="shrink-0 p-3 bg-accent rounded-lg h-fit">
|
||||||
|
<Icon className="h-5 w-5 text-primary" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h3 className="font-semibold text-foreground mb-1">{title}</h3>
|
||||||
|
<p className="text-sm text-muted-foreground leading-relaxed">{description}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* CTA */}
|
||||||
|
<div className="text-center space-y-4">
|
||||||
|
<h3 className="text-xl font-semibold text-foreground">Ready to get started?</h3>
|
||||||
|
<div className="flex items-center justify-center gap-3">
|
||||||
|
<Button onClick={scrollToLogin}>Sign in</Button>
|
||||||
|
<Button variant="outline" onClick={onSignUp}>
|
||||||
|
Create account
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Footer */}
|
||||||
|
<div className="border-t border-border">
|
||||||
|
<div className="max-w-5xl mx-auto px-6 py-6 flex items-center justify-between text-xs text-muted-foreground">
|
||||||
|
<span>© {new Date().getFullYear()} LabWise</span>
|
||||||
|
<span>Built for research labs</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
98
components/auth/ResetPassword.tsx
Normal file
98
components/auth/ResetPassword.tsx
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
import { useState } from 'react';
|
||||||
|
import { Button } from '../ui/button';
|
||||||
|
import { Card, CardContent } from '../ui/card';
|
||||||
|
import { Input } from '../ui/input';
|
||||||
|
import { Label } from '../ui/label';
|
||||||
|
import { resetPassword } from '../../lib/auth-client';
|
||||||
|
|
||||||
|
const logo = '/logo.png';
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
onSuccess: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ResetPassword({ onSuccess }: Props) {
|
||||||
|
const token = new URLSearchParams(window.location.search).get('token') || '';
|
||||||
|
const [password, setPassword] = useState('');
|
||||||
|
const [confirm, setConfirm] = useState('');
|
||||||
|
const [error, setError] = useState('');
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [done, setDone] = useState(false);
|
||||||
|
|
||||||
|
async function handleSubmit(e: React.FormEvent) {
|
||||||
|
e.preventDefault();
|
||||||
|
setError('');
|
||||||
|
if (password.length < 8) {
|
||||||
|
setError('Password must be at least 8 characters');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (password !== confirm) {
|
||||||
|
setError('Passwords do not match');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setLoading(true);
|
||||||
|
const res = await resetPassword({ newPassword: password, token });
|
||||||
|
setLoading(false);
|
||||||
|
if (res.error) {
|
||||||
|
setError(res.error.message || 'Failed to reset password. The link may have expired.');
|
||||||
|
} else {
|
||||||
|
setDone(true);
|
||||||
|
setTimeout(onSuccess, 2000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex h-screen items-center justify-center bg-secondary">
|
||||||
|
<Card className="w-full max-w-sm">
|
||||||
|
<CardContent className="p-8 space-y-6">
|
||||||
|
<div className="flex justify-center">
|
||||||
|
<img src={logo} alt="LabWise" className="h-12" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{done ? (
|
||||||
|
<div className="text-center space-y-2">
|
||||||
|
<h2 className="font-semibold text-lg">Password reset!</h2>
|
||||||
|
<p className="text-sm text-muted-foreground">Redirecting you to sign in…</p>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<div className="space-y-1">
|
||||||
|
<h2 className="font-semibold text-lg">Set new password</h2>
|
||||||
|
<p className="text-sm text-muted-foreground">Choose a new password for your account.</p>
|
||||||
|
</div>
|
||||||
|
<form onSubmit={handleSubmit} className="space-y-4">
|
||||||
|
<div className="space-y-1">
|
||||||
|
<Label htmlFor="password">New password</Label>
|
||||||
|
<Input
|
||||||
|
id="password"
|
||||||
|
type="password"
|
||||||
|
value={password}
|
||||||
|
onChange={e => setPassword(e.target.value)}
|
||||||
|
required
|
||||||
|
autoComplete="new-password"
|
||||||
|
placeholder="Min. 8 characters"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-1">
|
||||||
|
<Label htmlFor="confirm">Confirm password</Label>
|
||||||
|
<Input
|
||||||
|
id="confirm"
|
||||||
|
type="password"
|
||||||
|
value={confirm}
|
||||||
|
onChange={e => setConfirm(e.target.value)}
|
||||||
|
required
|
||||||
|
autoComplete="new-password"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{error && <p className="text-sm text-red-600">{error}</p>}
|
||||||
|
<Button type="submit" className="w-full" disabled={loading}>
|
||||||
|
{loading ? 'Resetting…' : 'Reset password'}
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
122
components/auth/SignUpForm.tsx
Normal file
122
components/auth/SignUpForm.tsx
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
import { useState } from 'react';
|
||||||
|
import { Button } from '../ui/button';
|
||||||
|
import { Card, CardContent } from '../ui/card';
|
||||||
|
import { Input } from '../ui/input';
|
||||||
|
import { Label } from '../ui/label';
|
||||||
|
import { signUp } from '../../lib/auth-client';
|
||||||
|
|
||||||
|
const logo = '/logo.png';
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
onLogin: () => void;
|
||||||
|
onVerify: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function SignUpForm({ onLogin, onVerify }: Props) {
|
||||||
|
const [name, setName] = useState('');
|
||||||
|
const [email, setEmail] = useState('');
|
||||||
|
const [password, setPassword] = useState('');
|
||||||
|
const [confirm, setConfirm] = useState('');
|
||||||
|
const [error, setError] = useState('');
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
async function handleSubmit(e: React.FormEvent) {
|
||||||
|
e.preventDefault();
|
||||||
|
setError('');
|
||||||
|
if (password.length < 8) {
|
||||||
|
setError('Password must be at least 8 characters');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (password !== confirm) {
|
||||||
|
setError('Passwords do not match');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setLoading(true);
|
||||||
|
const res = await signUp.email({
|
||||||
|
name,
|
||||||
|
email,
|
||||||
|
password,
|
||||||
|
callbackURL: window.location.origin,
|
||||||
|
});
|
||||||
|
setLoading(false);
|
||||||
|
if (res.error) {
|
||||||
|
setError(res.error.message || 'Failed to create account');
|
||||||
|
} else {
|
||||||
|
onVerify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex h-screen items-center justify-center bg-secondary">
|
||||||
|
<Card className="w-full max-w-sm">
|
||||||
|
<CardContent className="p-8 space-y-6">
|
||||||
|
<div className="flex justify-center">
|
||||||
|
<img src={logo} alt="LabWise" className="h-12" />
|
||||||
|
</div>
|
||||||
|
<p className="text-center text-muted-foreground text-sm">
|
||||||
|
Create your LabWise account.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<form onSubmit={handleSubmit} className="space-y-4">
|
||||||
|
<div className="space-y-1">
|
||||||
|
<Label htmlFor="name">Full name</Label>
|
||||||
|
<Input
|
||||||
|
id="name"
|
||||||
|
type="text"
|
||||||
|
value={name}
|
||||||
|
onChange={e => setName(e.target.value)}
|
||||||
|
required
|
||||||
|
autoComplete="name"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-1">
|
||||||
|
<Label htmlFor="email">Email</Label>
|
||||||
|
<Input
|
||||||
|
id="email"
|
||||||
|
type="email"
|
||||||
|
value={email}
|
||||||
|
onChange={e => setEmail(e.target.value)}
|
||||||
|
required
|
||||||
|
autoComplete="email"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-1">
|
||||||
|
<Label htmlFor="password">Password</Label>
|
||||||
|
<Input
|
||||||
|
id="password"
|
||||||
|
type="password"
|
||||||
|
value={password}
|
||||||
|
onChange={e => setPassword(e.target.value)}
|
||||||
|
required
|
||||||
|
autoComplete="new-password"
|
||||||
|
placeholder="Min. 8 characters"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-1">
|
||||||
|
<Label htmlFor="confirm">Confirm password</Label>
|
||||||
|
<Input
|
||||||
|
id="confirm"
|
||||||
|
type="password"
|
||||||
|
value={confirm}
|
||||||
|
onChange={e => setConfirm(e.target.value)}
|
||||||
|
required
|
||||||
|
autoComplete="new-password"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{error && <p className="text-sm text-red-600">{error}</p>}
|
||||||
|
<Button type="submit" className="w-full" disabled={loading}>
|
||||||
|
{loading ? 'Creating account…' : 'Create account'}
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<p className="text-center text-sm text-muted-foreground">
|
||||||
|
Already have an account?{' '}
|
||||||
|
<button onClick={onLogin} className="text-primary hover:underline font-medium">
|
||||||
|
Sign in
|
||||||
|
</button>
|
||||||
|
</p>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -4,4 +4,12 @@ export const authClient = createAuthClient({
|
|||||||
baseURL: `${window.location.origin}/api/auth`,
|
baseURL: `${window.location.origin}/api/auth`,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const { signIn, signOut, useSession } = authClient;
|
export const {
|
||||||
|
signIn,
|
||||||
|
signOut,
|
||||||
|
signUp,
|
||||||
|
useSession,
|
||||||
|
forgetPassword,
|
||||||
|
resetPassword,
|
||||||
|
sendVerificationEmail,
|
||||||
|
} = authClient;
|
||||||
|
|||||||
1276
server/package-lock.json
generated
1276
server/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -9,6 +9,7 @@
|
|||||||
"db:migrate": "tsx src/db/migrate.ts"
|
"db:migrate": "tsx src/db/migrate.ts"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@aws-sdk/client-ses": "^3.1013.0",
|
||||||
"better-auth": "^1.5.5",
|
"better-auth": "^1.5.5",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"express": "^4.21.2",
|
"express": "^4.21.2",
|
||||||
|
|||||||
@@ -2,11 +2,13 @@ import { betterAuth } from 'better-auth';
|
|||||||
import { kyselyAdapter } from '@better-auth/kysely-adapter';
|
import { kyselyAdapter } from '@better-auth/kysely-adapter';
|
||||||
import { Kysely, PostgresDialect } from 'kysely';
|
import { Kysely, PostgresDialect } from 'kysely';
|
||||||
import { Pool } from 'pg';
|
import { Pool } from 'pg';
|
||||||
|
import { sendEmail, verificationEmailHtml, resetPasswordEmailHtml } from './email';
|
||||||
|
|
||||||
const db = new Kysely({
|
const db = new Kysely({
|
||||||
dialect: new PostgresDialect({
|
dialect: new PostgresDialect({
|
||||||
pool: new Pool({
|
pool: new Pool({
|
||||||
connectionString: process.env.DATABASE_URL ||
|
connectionString:
|
||||||
|
process.env.DATABASE_URL ||
|
||||||
'postgresql://labwise:labwise_dev_pw@localhost:5432/labwise_db',
|
'postgresql://labwise:labwise_dev_pw@localhost:5432/labwise_db',
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
@@ -16,7 +18,35 @@ export const auth = betterAuth({
|
|||||||
database: kyselyAdapter(db, { type: 'postgres' }),
|
database: kyselyAdapter(db, { type: 'postgres' }),
|
||||||
|
|
||||||
baseURL: process.env.BETTER_AUTH_URL || 'http://localhost:3001',
|
baseURL: process.env.BETTER_AUTH_URL || 'http://localhost:3001',
|
||||||
secret: process.env.BETTER_AUTH_SECRET || 'dev-secret-change-in-production-min32chars!!',
|
secret:
|
||||||
|
process.env.BETTER_AUTH_SECRET ||
|
||||||
|
'dev-secret-change-in-production-min32chars!!',
|
||||||
|
|
||||||
|
rateLimit: {
|
||||||
|
enabled: false, // TODO: re-enable in production
|
||||||
|
},
|
||||||
|
|
||||||
|
emailAndPassword: {
|
||||||
|
enabled: true,
|
||||||
|
requireEmailVerification: true,
|
||||||
|
sendResetPassword: async ({ user, url }) => {
|
||||||
|
await sendEmail({
|
||||||
|
to: user.email,
|
||||||
|
subject: 'Reset your LabWise password',
|
||||||
|
html: resetPasswordEmailHtml(url),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
emailVerification: {
|
||||||
|
sendVerificationEmail: async ({ user, url }) => {
|
||||||
|
await sendEmail({
|
||||||
|
to: user.email,
|
||||||
|
subject: 'Verify your LabWise email',
|
||||||
|
html: verificationEmailHtml(url),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
socialProviders: {
|
socialProviders: {
|
||||||
google: {
|
google: {
|
||||||
|
|||||||
47
server/src/auth/email.ts
Normal file
47
server/src/auth/email.ts
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
import { SESClient, SendEmailCommand } from '@aws-sdk/client-ses';
|
||||||
|
|
||||||
|
const ses = new SESClient({ region: process.env.AWS_REGION || 'us-east-1' });
|
||||||
|
const FROM = process.env.FROM_EMAIL || 'noreply@labwise.wahwa.com';
|
||||||
|
|
||||||
|
export async function sendEmail({
|
||||||
|
to,
|
||||||
|
subject,
|
||||||
|
html,
|
||||||
|
}: {
|
||||||
|
to: string;
|
||||||
|
subject: string;
|
||||||
|
html: string;
|
||||||
|
}) {
|
||||||
|
await ses.send(
|
||||||
|
new SendEmailCommand({
|
||||||
|
Source: FROM,
|
||||||
|
Destination: { ToAddresses: [to] },
|
||||||
|
Message: {
|
||||||
|
Subject: { Data: subject },
|
||||||
|
Body: { Html: { Data: html } },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function verificationEmailHtml(url: string) {
|
||||||
|
return `
|
||||||
|
<div style="font-family:sans-serif;max-width:480px;margin:0 auto;padding:32px">
|
||||||
|
<h2 style="color:#2d5a4a;margin-bottom:8px">Verify your email</h2>
|
||||||
|
<p style="color:#555;margin-bottom:24px">Click the button below to verify your email address and activate your LabWise account.</p>
|
||||||
|
<a href="${url}" style="display:inline-block;background:#5a9584;color:white;padding:12px 28px;border-radius:6px;text-decoration:none;font-weight:600">Verify Email</a>
|
||||||
|
<p style="color:#aaa;font-size:12px;margin-top:32px">If you didn't create a LabWise account, you can ignore this email.</p>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resetPasswordEmailHtml(url: string) {
|
||||||
|
return `
|
||||||
|
<div style="font-family:sans-serif;max-width:480px;margin:0 auto;padding:32px">
|
||||||
|
<h2 style="color:#2d5a4a;margin-bottom:8px">Reset your password</h2>
|
||||||
|
<p style="color:#555;margin-bottom:24px">Click the button below to reset your LabWise password. This link expires in 1 hour.</p>
|
||||||
|
<a href="${url}" style="display:inline-block;background:#5a9584;color:white;padding:12px 28px;border-radius:6px;text-decoration:none;font-weight:600">Reset Password</a>
|
||||||
|
<p style="color:#aaa;font-size:12px;margin-top:32px">If you didn't request this, you can ignore this email.</p>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
@@ -108,3 +108,14 @@ CREATE TABLE IF NOT EXISTS protocols (
|
|||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX IF NOT EXISTS protocols_user_id_idx ON protocols(user_id);
|
CREATE INDEX IF NOT EXISTS protocols_user_id_idx ON protocols(user_id);
|
||||||
|
|
||||||
|
-- User profile — lab defaults pre-filled on chemical entries
|
||||||
|
CREATE TABLE IF NOT EXISTS user_profile (
|
||||||
|
user_id TEXT NOT NULL PRIMARY KEY REFERENCES "user"("id") ON DELETE CASCADE,
|
||||||
|
pi_first_name TEXT NOT NULL,
|
||||||
|
bldg_code TEXT NOT NULL,
|
||||||
|
lab TEXT NOT NULL,
|
||||||
|
contact TEXT,
|
||||||
|
created_at TIMESTAMPTZ DEFAULT NOW(),
|
||||||
|
updated_at TIMESTAMPTZ DEFAULT NOW()
|
||||||
|
);
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ import { auth } from './auth/auth';
|
|||||||
import { authRateLimiter, apiRateLimiter } from './auth/rateLimiter';
|
import { authRateLimiter, apiRateLimiter } from './auth/rateLimiter';
|
||||||
import chemicalsRouter from './routes/chemicals';
|
import chemicalsRouter from './routes/chemicals';
|
||||||
import protocolsRouter from './routes/protocols';
|
import protocolsRouter from './routes/protocols';
|
||||||
|
import profileRouter from './routes/profile';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
console.log(process.env.BETTER_AUTH_URL, process.env.BETTER_AUTH_SECRET);
|
|
||||||
const PORT = process.env.PORT || 3001;
|
const PORT = process.env.PORT || 3001;
|
||||||
const UPLOADS_DIR = process.env.UPLOADS_DIR || path.join(__dirname, '../uploads');
|
const UPLOADS_DIR = process.env.UPLOADS_DIR || path.join(__dirname, '../uploads');
|
||||||
|
|
||||||
@@ -38,11 +38,10 @@ app.use(express.json({ limit: '1mb' }));
|
|||||||
app.use('/api', apiRateLimiter);
|
app.use('/api', apiRateLimiter);
|
||||||
app.use('/api/chemicals', chemicalsRouter);
|
app.use('/api/chemicals', chemicalsRouter);
|
||||||
app.use('/api/protocols', protocolsRouter);
|
app.use('/api/protocols', protocolsRouter);
|
||||||
|
app.use('/api/profile', profileRouter);
|
||||||
|
|
||||||
app.get('/api/health', (_req, res) => res.json({ ok: true }));
|
app.get('/api/health', (_req, res) => res.json({ ok: true }));
|
||||||
|
|
||||||
app.listen(PORT, () => {
|
app.listen(PORT, () => {
|
||||||
console.log(`LabWise API running on http://localhost:${PORT}`);
|
console.log(`LabWise API running on http://localhost:${PORT}`);
|
||||||
console.log('BETTER_AUTH_URL:', process.env.BETTER_AUTH_URL);
|
|
||||||
console.log('BETTER_AUTH_SECRET:', process.env.BETTER_AUTH_SECRET);
|
|
||||||
});
|
});
|
||||||
|
|||||||
46
server/src/routes/profile.ts
Normal file
46
server/src/routes/profile.ts
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
import { Router } from 'express';
|
||||||
|
import { requireAuth } from '../auth/middleware';
|
||||||
|
import { pool } from '../db/pool';
|
||||||
|
|
||||||
|
const router = Router();
|
||||||
|
|
||||||
|
router.get('/', requireAuth, async (req, res) => {
|
||||||
|
try {
|
||||||
|
const result = await pool.query(
|
||||||
|
'SELECT * FROM user_profile WHERE user_id = $1',
|
||||||
|
[req.user!.id]
|
||||||
|
);
|
||||||
|
if (result.rows.length === 0) {
|
||||||
|
return res.status(404).json({ error: 'Profile not found' });
|
||||||
|
}
|
||||||
|
res.json(result.rows[0]);
|
||||||
|
} catch {
|
||||||
|
res.status(500).json({ error: 'Server error' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
router.post('/', requireAuth, async (req, res) => {
|
||||||
|
const { pi_first_name, bldg_code, lab, contact } = req.body;
|
||||||
|
if (!pi_first_name || !bldg_code || !lab) {
|
||||||
|
return res.status(400).json({ error: 'pi_first_name, bldg_code, and lab are required' });
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const result = await pool.query(
|
||||||
|
`INSERT INTO user_profile (user_id, pi_first_name, bldg_code, lab, contact)
|
||||||
|
VALUES ($1, $2, $3, $4, $5)
|
||||||
|
ON CONFLICT (user_id) DO UPDATE SET
|
||||||
|
pi_first_name = EXCLUDED.pi_first_name,
|
||||||
|
bldg_code = EXCLUDED.bldg_code,
|
||||||
|
lab = EXCLUDED.lab,
|
||||||
|
contact = EXCLUDED.contact,
|
||||||
|
updated_at = NOW()
|
||||||
|
RETURNING *`,
|
||||||
|
[req.user!.id, pi_first_name, bldg_code, lab, contact || null]
|
||||||
|
);
|
||||||
|
res.json(result.rows[0]);
|
||||||
|
} catch {
|
||||||
|
res.status(500).json({ error: 'Server error' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export default router;
|
||||||
Reference in New Issue
Block a user