Skip to content

Commit f62883e

Browse files
committed
feat(web): authentication with Firebase, NextAuth v5, and sidebar dashboard (closes #37)
- NextAuth v5 (Auth.js) with a single Credentials provider that accepts Firebase ID tokens — Google OAuth and email/password both flow through Firebase Auth SDK on the client, then exchange the ID token for a NextAuth session - proxy.ts (Next.js 16 convention) protects /dashboard and /settings, redirecting unauthenticated users to /login - tRPC protectedProcedure updated to use NextAuth auth() for session validation; TRPCContext now carries Session | null - Login, Register, and Google Sign-In pages with shadcn Card + Form + react-hook-form + Zod validation; errors surfaced via Sonner toasts - Dashboard layout with shadcn Sidebar (AppSidebar), collapsible trigger, and UserMenu (avatar + dropdown) in the sidebar footer - Settings page added so sidebar nav link resolves without 404 - Header component wired into home page; "App" logo links home - Manrope replaces Geist Sans as the global font - next.config.ts allows lh3.googleusercontent.com for Google profile pics - Shared lib/firebase.ts initialises the Firebase app and exports getFirebaseAuth() for use across client components - .env.example updated with all required vars; both backend and web examples verified complete - 79 Vitest tests pass (19 test files)
1 parent 290ca07 commit f62883e

49 files changed

Lines changed: 2613 additions & 86 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎web/.env.example‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,21 @@
11
# Sentry DSN for error tracking (optional; leave empty to disable)
22
NEXT_PUBLIC_SENTRY_DSN=
3+
4+
# NextAuth.js — required for session management
5+
AUTH_SECRET= # openssl rand -base64 32
6+
7+
# Firebase — client-side config (copy from Firebase Console > Project settings)
8+
NEXT_PUBLIC_FIREBASE_API_KEY=
9+
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=
10+
NEXT_PUBLIC_FIREBASE_PROJECT_ID=
11+
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=
12+
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=
13+
NEXT_PUBLIC_FIREBASE_APP_ID=
14+
NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID= # optional
15+
16+
# Firebase Cloud Messaging — VAPID key from Firebase Console > Cloud Messaging
17+
NEXT_PUBLIC_FIREBASE_VAPID_KEY=
18+
19+
# Go backend base URL
20+
NEXT_PUBLIC_API_URL=http://localhost:8080
21+

‎web/__tests__/page.test.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { render } from '@testing-library/react'
2-
import { describe, it, expect } from 'vitest'
2+
import { describe, it, expect, vi } from 'vitest'
33
import Home from '../app/page'
44

5+
vi.mock('next-auth/react', () => ({
6+
useSession: vi.fn(() => ({ data: null, status: 'unauthenticated' })),
7+
SessionProvider: ({ children }: { children: React.ReactNode }) => <>{children}</>,
8+
}))
9+
510
describe('Home page', () => {
611
it('renders without crashing', () => {
712
const { container } = render(<Home />)

‎web/app/(auth)/login/page.tsx‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import {
2+
Card,
3+
CardContent,
4+
CardDescription,
5+
CardHeader,
6+
CardTitle,
7+
} from '@/components/ui/card'
8+
import { LoginForm } from '@/features/auth/components/LoginForm'
9+
import { GoogleSignInButton } from '@/features/auth/components/GoogleSignInButton'
10+
import { Separator } from '@/components/ui/separator'
11+
import Link from 'next/link'
12+
13+
export default function LoginPage() {
14+
return (
15+
<div className="flex min-h-screen items-center justify-center p-4">
16+
<Card className="w-full max-w-sm">
17+
<CardHeader>
18+
<CardTitle className="text-2xl">Sign in</CardTitle>
19+
<CardDescription>
20+
Enter your credentials to access your account
21+
</CardDescription>
22+
</CardHeader>
23+
<CardContent className="space-y-4">
24+
<GoogleSignInButton />
25+
<div className="flex items-center gap-4">
26+
<Separator className="flex-1" />
27+
<span className="text-muted-foreground text-xs">or</span>
28+
<Separator className="flex-1" />
29+
</div>
30+
<LoginForm />
31+
<p className="text-muted-foreground text-center text-sm">
32+
Don&apos;t have an account?{' '}
33+
<Link
34+
href="/register"
35+
className="text-primary underline-offset-4 hover:underline"
36+
>
37+
Sign up
38+
</Link>
39+
</p>
40+
</CardContent>
41+
</Card>
42+
</div>
43+
)
44+
}

‎web/app/(auth)/register/page.tsx‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import {
2+
Card,
3+
CardContent,
4+
CardDescription,
5+
CardHeader,
6+
CardTitle,
7+
} from '@/components/ui/card'
8+
import { RegisterForm } from '@/features/auth/components/RegisterForm'
9+
import { GoogleSignInButton } from '@/features/auth/components/GoogleSignInButton'
10+
import { Separator } from '@/components/ui/separator'
11+
import Link from 'next/link'
12+
13+
export default function RegisterPage() {
14+
return (
15+
<div className="flex min-h-screen items-center justify-center p-4">
16+
<Card className="w-full max-w-sm">
17+
<CardHeader>
18+
<CardTitle className="text-2xl">Create account</CardTitle>
19+
<CardDescription>Sign up to get started</CardDescription>
20+
</CardHeader>
21+
<CardContent className="space-y-4">
22+
<GoogleSignInButton />
23+
<div className="flex items-center gap-4">
24+
<Separator className="flex-1" />
25+
<span className="text-muted-foreground text-xs">or</span>
26+
<Separator className="flex-1" />
27+
</div>
28+
<RegisterForm />
29+
<p className="text-muted-foreground text-center text-sm">
30+
Already have an account?{' '}
31+
<Link
32+
href="/login"
33+
className="text-primary underline-offset-4 hover:underline"
34+
>
35+
Sign in
36+
</Link>
37+
</p>
38+
</CardContent>
39+
</Card>
40+
</div>
41+
)
42+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { auth } from '@/auth'
2+
import { redirect } from 'next/navigation'
3+
4+
export default async function DashboardPage() {
5+
const session = await auth()
6+
if (!session) redirect('/login')
7+
8+
return (
9+
<div className="flex flex-1 items-center justify-center">
10+
<div className="text-center">
11+
<h1 className="text-3xl font-bold">Welcome back</h1>
12+
<p className="mt-2 text-muted-foreground">
13+
{session.user?.name ?? session.user?.email ?? 'User'}
14+
</p>
15+
</div>
16+
</div>
17+
)
18+
}

‎web/app/(dashboard)/layout.tsx‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { SidebarInset, SidebarProvider, SidebarTrigger } from '@/components/ui/sidebar'
2+
import { AppSidebar } from '@/components/layout/AppSidebar'
3+
4+
export default function DashboardLayout({ children }: { children: React.ReactNode }) {
5+
return (
6+
<SidebarProvider className="flex flex-1">
7+
<AppSidebar />
8+
<SidebarInset className="flex flex-col">
9+
<header className="flex h-12 shrink-0 items-center border-b px-4">
10+
<SidebarTrigger />
11+
</header>
12+
<div className="flex flex-1 flex-col">{children}</div>
13+
</SidebarInset>
14+
</SidebarProvider>
15+
)
16+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { auth } from '@/auth'
2+
import { redirect } from 'next/navigation'
3+
4+
export default async function SettingsPage() {
5+
const session = await auth()
6+
if (!session) redirect('/login')
7+
8+
return (
9+
<div className="flex flex-1 flex-col gap-6 p-8">
10+
<div>
11+
<h1 className="text-2xl font-bold">Settings</h1>
12+
<p className="mt-1 text-muted-foreground">Manage your account settings.</p>
13+
</div>
14+
<div className="rounded-lg border p-6">
15+
<h2 className="text-sm font-medium">Account</h2>
16+
<p className="mt-1 text-sm text-muted-foreground">
17+
{session.user?.name && (
18+
<span className="block">{session.user.name}</span>
19+
)}
20+
{session.user?.email}
21+
</p>
22+
</div>
23+
</div>
24+
)
25+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import { handlers } from "@/auth"
2+
export const { GET, POST } = handlers

‎web/app/layout.tsx‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import type { Metadata } from "next";
2-
import { Geist, Geist_Mono } from "next/font/google";
2+
import { Manrope, Geist_Mono } from "next/font/google";
33
import "./globals.css";
44
import { Providers } from "./providers";
55

6-
const geistSans = Geist({
7-
variable: "--font-geist-sans",
6+
const manrope = Manrope({
7+
variable: "--font-sans",
88
subsets: ["latin"],
99
});
1010

@@ -14,8 +14,8 @@ const geistMono = Geist_Mono({
1414
});
1515

1616
export const metadata: Metadata = {
17-
title: "Create Next App",
18-
description: "Generated by create next app",
17+
title: "App",
18+
description: "Fullstack template",
1919
};
2020

2121
export default function RootLayout({
@@ -26,7 +26,7 @@ export default function RootLayout({
2626
return (
2727
<html
2828
lang="en"
29-
className={`${geistSans.variable} ${geistMono.variable} h-full antialiased`}
29+
className={`${manrope.variable} ${geistMono.variable} h-full antialiased`}
3030
>
3131
<body className="min-h-full flex flex-col">
3232
<Providers>{children}</Providers>

‎web/app/page.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import About from "@/components/home/about";
22
import Hero from "@/components/home/hero";
3+
import Footer from "@/components/layout/footer";
4+
import Header from "@/components/layout/header";
35

46
const page = () => {
57
return (
68
<div>
9+
<Header />
710
<Hero />
811
<About />
12+
<Footer />
913
</div>
1014
);
1115
};

0 commit comments

Comments
 (0)