Skip to content

Commit a9940c6

Browse files
authored
Merge pull request #42 from GRACENOBLE/37-feat-web-auth
feat(web): authentication with Firebase, NextAuth v5, and sidebar dashboard
2 parents 290ca07 + 4e491c6 commit a9940c6

51 files changed

Lines changed: 3696 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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,27 @@
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 Admin SDK — server-side token verification
8+
# Set FIREBASE_SERVICE_ACCOUNT_JSON to the full service account JSON (single line, no newlines).
9+
# If omitted, set FIREBASE_PROJECT_ID and rely on Application Default Credentials (GCP only).
10+
FIREBASE_PROJECT_ID= # same as NEXT_PUBLIC_FIREBASE_PROJECT_ID, server-side only
11+
FIREBASE_SERVICE_ACCOUNT_JSON= # {"type":"service_account","project_id":"..."}
12+
13+
# Firebase — client-side config (copy from Firebase Console > Project settings)
14+
NEXT_PUBLIC_FIREBASE_API_KEY=
15+
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=
16+
NEXT_PUBLIC_FIREBASE_PROJECT_ID=
17+
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=
18+
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=
19+
NEXT_PUBLIC_FIREBASE_APP_ID=
20+
NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID= # optional
21+
22+
# Firebase Cloud Messaging — VAPID key from Firebase Console > Cloud Messaging
23+
NEXT_PUBLIC_FIREBASE_VAPID_KEY=
24+
25+
# Go backend base URL
26+
NEXT_PUBLIC_API_URL=http://localhost:8080
27+

‎web/__mocks__/next/image.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { ImageProps } from 'next/image'
22

33
export default function MockImage({ src, alt, width, height, ...props }: ImageProps) {
44
return (
5+
// eslint-disable-next-line @next/next/no-img-element
56
<img
67
src={typeof src === 'string' ? src : ''}
78
alt={alt}

‎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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { cookies } from 'next/headers'
2+
import { SidebarInset, SidebarProvider, SidebarTrigger } from '@/components/ui/sidebar'
3+
import { AppSidebar } from '@/components/layout/AppSidebar'
4+
5+
export default async function DashboardLayout({ children }: { children: React.ReactNode }) {
6+
const cookieStore = await cookies()
7+
const sidebarOpen = cookieStore.get('sidebar_state')?.value !== 'false'
8+
9+
return (
10+
<SidebarProvider defaultOpen={sidebarOpen} className="flex flex-1">
11+
<AppSidebar />
12+
<SidebarInset className="flex flex-col">
13+
<header className="flex h-12 shrink-0 items-center border-b px-4">
14+
<SidebarTrigger />
15+
</header>
16+
<div className="flex flex-1 flex-col">{children}</div>
17+
</SidebarInset>
18+
</SidebarProvider>
19+
)
20+
}
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>

0 commit comments

Comments
 (0)