From 075e6dd9eaf4bc265affa6ecaabbe1b76c21a227 Mon Sep 17 00:00:00 2001 From: schererleander Date: Wed, 2 Jul 2025 22:18:28 +0200 Subject: feat: add app pages and layout --- src/app/favicon.ico | Bin 0 -> 25931 bytes src/app/globals.css | 122 ++++++++++++ src/app/layout.tsx | 34 ++++ src/app/login/page.tsx | 149 ++++++++++++++ src/app/page.tsx | 53 +++++ src/app/settings/page.tsx | 491 ++++++++++++++++++++++++++++++++++++++++++++++ src/app/signup/page.tsx | 208 ++++++++++++++++++++ 7 files changed, 1057 insertions(+) create mode 100644 src/app/favicon.ico create mode 100644 src/app/globals.css create mode 100644 src/app/layout.tsx create mode 100644 src/app/login/page.tsx create mode 100644 src/app/page.tsx create mode 100644 src/app/settings/page.tsx create mode 100644 src/app/signup/page.tsx diff --git a/src/app/favicon.ico b/src/app/favicon.ico new file mode 100644 index 0000000..718d6fe Binary files /dev/null and b/src/app/favicon.ico differ diff --git a/src/app/globals.css b/src/app/globals.css new file mode 100644 index 0000000..dc98be7 --- /dev/null +++ b/src/app/globals.css @@ -0,0 +1,122 @@ +@import "tailwindcss"; +@import "tw-animate-css"; + +@custom-variant dark (&:is(.dark *)); + +@theme inline { + --color-background: var(--background); + --color-foreground: var(--foreground); + --font-sans: var(--font-geist-sans); + --font-mono: var(--font-geist-mono); + --color-sidebar-ring: var(--sidebar-ring); + --color-sidebar-border: var(--sidebar-border); + --color-sidebar-accent-foreground: var(--sidebar-accent-foreground); + --color-sidebar-accent: var(--sidebar-accent); + --color-sidebar-primary-foreground: var(--sidebar-primary-foreground); + --color-sidebar-primary: var(--sidebar-primary); + --color-sidebar-foreground: var(--sidebar-foreground); + --color-sidebar: var(--sidebar); + --color-chart-5: var(--chart-5); + --color-chart-4: var(--chart-4); + --color-chart-3: var(--chart-3); + --color-chart-2: var(--chart-2); + --color-chart-1: var(--chart-1); + --color-ring: var(--ring); + --color-input: var(--input); + --color-border: var(--border); + --color-destructive: var(--destructive); + --color-accent-foreground: var(--accent-foreground); + --color-accent: var(--accent); + --color-muted-foreground: var(--muted-foreground); + --color-muted: var(--muted); + --color-secondary-foreground: var(--secondary-foreground); + --color-secondary: var(--secondary); + --color-primary-foreground: var(--primary-foreground); + --color-primary: var(--primary); + --color-popover-foreground: var(--popover-foreground); + --color-popover: var(--popover); + --color-card-foreground: var(--card-foreground); + --color-card: var(--card); + --radius-sm: calc(var(--radius) - 4px); + --radius-md: calc(var(--radius) - 2px); + --radius-lg: var(--radius); + --radius-xl: calc(var(--radius) + 4px); +} + +:root { + --radius: 0.625rem; + --background: oklch(1 0 0); + --foreground: oklch(0.145 0 0); + --card: oklch(1 0 0); + --card-foreground: oklch(0.145 0 0); + --popover: oklch(1 0 0); + --popover-foreground: oklch(0.145 0 0); + --primary: oklch(0.205 0 0); + --primary-foreground: oklch(0.985 0 0); + --secondary: oklch(0.97 0 0); + --secondary-foreground: oklch(0.205 0 0); + --muted: oklch(0.97 0 0); + --muted-foreground: oklch(0.556 0 0); + --accent: oklch(0.97 0 0); + --accent-foreground: oklch(0.205 0 0); + --destructive: oklch(0.577 0.245 27.325); + --border: oklch(0.922 0 0); + --input: oklch(0.922 0 0); + --ring: oklch(0.708 0 0); + --chart-1: oklch(0.646 0.222 41.116); + --chart-2: oklch(0.6 0.118 184.704); + --chart-3: oklch(0.398 0.07 227.392); + --chart-4: oklch(0.828 0.189 84.429); + --chart-5: oklch(0.769 0.188 70.08); + --sidebar: oklch(0.985 0 0); + --sidebar-foreground: oklch(0.145 0 0); + --sidebar-primary: oklch(0.205 0 0); + --sidebar-primary-foreground: oklch(0.985 0 0); + --sidebar-accent: oklch(0.97 0 0); + --sidebar-accent-foreground: oklch(0.205 0 0); + --sidebar-border: oklch(0.922 0 0); + --sidebar-ring: oklch(0.708 0 0); +} + +.dark { + --background: oklch(0.145 0 0); + --foreground: oklch(0.985 0 0); + --card: oklch(0.205 0 0); + --card-foreground: oklch(0.985 0 0); + --popover: oklch(0.205 0 0); + --popover-foreground: oklch(0.985 0 0); + --primary: oklch(0.922 0 0); + --primary-foreground: oklch(0.205 0 0); + --secondary: oklch(0.269 0 0); + --secondary-foreground: oklch(0.985 0 0); + --muted: oklch(0.269 0 0); + --muted-foreground: oklch(0.708 0 0); + --accent: oklch(0.269 0 0); + --accent-foreground: oklch(0.985 0 0); + --destructive: oklch(0.704 0.191 22.216); + --border: oklch(1 0 0 / 10%); + --input: oklch(1 0 0 / 15%); + --ring: oklch(0.556 0 0); + --chart-1: oklch(0.488 0.243 264.376); + --chart-2: oklch(0.696 0.17 162.48); + --chart-3: oklch(0.769 0.188 70.08); + --chart-4: oklch(0.627 0.265 303.9); + --chart-5: oklch(0.645 0.246 16.439); + --sidebar: oklch(0.205 0 0); + --sidebar-foreground: oklch(0.985 0 0); + --sidebar-primary: oklch(0.488 0.243 264.376); + --sidebar-primary-foreground: oklch(0.985 0 0); + --sidebar-accent: oklch(0.269 0 0); + --sidebar-accent-foreground: oklch(0.985 0 0); + --sidebar-border: oklch(1 0 0 / 10%); + --sidebar-ring: oklch(0.556 0 0); +} + +@layer base { + * { + @apply border-border outline-ring/50; + } + body { + @apply bg-background text-foreground; + } +} diff --git a/src/app/layout.tsx b/src/app/layout.tsx new file mode 100644 index 0000000..35e95b1 --- /dev/null +++ b/src/app/layout.tsx @@ -0,0 +1,34 @@ +import type { Metadata } from "next"; +import "./globals.css"; +import AuthSessionProvider from "@/components/SessionProvider"; +import { Toaster } from "@/components/ui/toast"; +import { ThemeProvider } from "@/components/ThemeProvider"; + +export const metadata: Metadata = { + title: "Boilerplate", + description: "Boilerplate for Next.js", +}; + +export default function RootLayout({ + children, +}: Readonly<{ + children: React.ReactNode; +}>) { + return ( + + + + + {children} + + + + + + ); +} diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx new file mode 100644 index 0000000..7d4ad9d --- /dev/null +++ b/src/app/login/page.tsx @@ -0,0 +1,149 @@ +"use client" + +import { useState } from "react" +import { signIn } from "next-auth/react" +import { useRouter } from "next/navigation" +import { zodResolver } from "@hookform/resolvers/zod" +import { useForm } from "react-hook-form" +import { Eye, EyeOff, Loader2 } from "lucide-react" +import Link from "next/link" + +import { Button } from "@/components/ui/button" +import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" +import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form" +import { Input } from "@/components/ui/input" +import { Alert, AlertDescription } from "@/components/ui/alert" + +import { loginSchema, type LoginInput } from "@/lib/validation" + +export default function SignInPage() { + const [showPassword, setShowPassword] = useState(false) + const [isLoading, setIsLoading] = useState(false) + const [error, setError] = useState("") + const router = useRouter() + + const form = useForm({ + resolver: zodResolver(loginSchema), + defaultValues: { + email: "", + password: "", + }, + }) + + const onSubmit = async (data: LoginInput) => { + setIsLoading(true) + setError("") + + try { + const result = await signIn("credentials", { + email: data.email, + password: data.password, + redirect: false, + }) + + if (result?.error) { + setError("Invalid email or password") + } else { + router.push("/") + router.refresh() + } + } catch (error) { + setError("An unexpected error occurred") + } finally { + setIsLoading(false) + } + } + + return ( +
+ + + Sign In + + Enter your email and password to access your account + + + + {error && ( + + {error} + + )} + +
+ + ( + + Email + + + + + + )} + /> + ( + + Password + +
+ + +
+
+ +
+ )} + /> + + + + +
+ Don't have an account? + + Sign up + +
+ +
+ +
+
+
+
+ ) +} \ No newline at end of file diff --git a/src/app/page.tsx b/src/app/page.tsx new file mode 100644 index 0000000..bc498c7 --- /dev/null +++ b/src/app/page.tsx @@ -0,0 +1,53 @@ +"use client" + +import Link from "next/link" +import { Button } from "@/components/ui/button" +import Navbar from "@/components/Navbar" +import Footer from "@/components/Footer" +import { LogIn, ArrowRight } from "lucide-react" + +export default function Home() { + return ( +
+ + +
+
+
+
+

+ Build Something + Amazing +

+

+ A modern Next.js application with beautiful UI components, + secure authentication, and everything you need to build your next project. +

+
+ +
+ + +
+ +
+

+ Built with Next.js, Tailwind CSS, Shadcn/UI, and MongoDB +

+
+
+
+
+ +
+
+ ) +} \ No newline at end of file diff --git a/src/app/settings/page.tsx b/src/app/settings/page.tsx new file mode 100644 index 0000000..ce2d849 --- /dev/null +++ b/src/app/settings/page.tsx @@ -0,0 +1,491 @@ +"use client" + +import { useState, useEffect, useRef } from "react" +import { useSession } from "next-auth/react" +import { useRouter } from "next/navigation" +import { zodResolver } from "@hookform/resolvers/zod" +import { useForm } from "react-hook-form" +import { z } from "zod" +import { Eye, EyeOff, Loader2, User, Mail, Lock, Save, Camera, Upload, Trash2 } from "lucide-react" +import { toast } from "sonner" + +import { Button } from "@/components/ui/button" +import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" +import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form" +import { Input } from "@/components/ui/input" +import { Separator } from "@/components/ui/separator" +import { Avatar, AvatarImage, AvatarFallback } from "@/components/ui/avatar" +import Navbar from "@/components/Navbar" +import { updateProfileSchema, updatePasswordSchema, type UpdateProfileInput, type UpdatePasswordInput } from "@/lib/validation" + +// Form schema for password change with confirmation +const passwordChangeSchema = updatePasswordSchema.extend({ + confirmPassword: z.string() +}).refine((data) => data.newPassword === data.confirmPassword, { + message: "Passwords don't match", + path: ["confirmPassword"], +}) + +type ProfileFormData = UpdateProfileInput +type PasswordFormData = z.infer + +export default function SettingsPage() { + const { data: session, status, update } = useSession() + const router = useRouter() + const fileInputRef = useRef(null) + const [showCurrentPassword, setShowCurrentPassword] = useState(false) + const [showNewPassword, setShowNewPassword] = useState(false) + const [showConfirmPassword, setShowConfirmPassword] = useState(false) + const [isLoading, setIsLoading] = useState(false) + const [isImageLoading, setIsImageLoading] = useState(false) + const [profileImageUrl, setProfileImageUrl] = useState(null) + + const profileForm = useForm({ + resolver: zodResolver(updateProfileSchema), + defaultValues: { + name: "", + email: "", + }, + }) + + const passwordForm = useForm({ + resolver: zodResolver(passwordChangeSchema), + defaultValues: { + currentPassword: "", + newPassword: "", + confirmPassword: "", + }, + }) + + // Redirect if not authenticated + useEffect(() => { + if (status === "unauthenticated") { + router.push("/login") + } + }, [status, router]) + + // Set form values when session is loaded + useEffect(() => { + if (session?.user) { + profileForm.reset({ + name: session.user.name || "", + email: session.user.email || "", + }) + setProfileImageUrl(session.user.image || null) + } + }, [session, profileForm]) + + const onProfileSubmit = async (data: ProfileFormData) => { + setIsLoading(true) + + try { + const response = await fetch("/api/user/profile", { + method: "PATCH", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(data), + }) + + const result = await response.json() + + if (!response.ok) { + toast.error(result.error || "Failed to update profile") + return + } + + // Update the session with new data + await update({ + name: data.name, + email: data.email, + }) + + toast.success("Profile updated successfully!") + + } catch (error) { + toast.error("An unexpected error occurred") + } finally { + setIsLoading(false) + } + } + + const onPasswordSubmit = async (data: PasswordFormData) => { + setIsLoading(true) + + try { + const response = await fetch("/api/user/password", { + method: "PATCH", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + currentPassword: data.currentPassword, + newPassword: data.newPassword, + }), + }) + + const result = await response.json() + + if (!response.ok) { + toast.error(result.error || "Failed to update password") + return + } + + toast.success("Password updated successfully!") + passwordForm.reset() + + } catch (error) { + toast.error("An unexpected error occurred") + } finally { + setIsLoading(false) + } + } + + const handleImageUpload = async (event: React.ChangeEvent) => { + const file = event.target.files?.[0] + if (!file) return + + setIsImageLoading(true) + + try { + const formData = new FormData() + formData.append('image', file) + + const response = await fetch('/api/user/profile-image', { + method: 'POST', + body: formData, + }) + + const result = await response.json() + + if (!response.ok) { + toast.error(result.error || 'Failed to upload image') + return + } + + setProfileImageUrl(result.profileImage.url) + toast.success('Profile image uploaded successfully!') + + // Update session with new image + await update({ + image: result.profileImage.url + }) + + } catch (error) { + toast.error('An unexpected error occurred') + } finally { + setIsImageLoading(false) + // Reset file input + if (fileInputRef.current) { + fileInputRef.current.value = '' + } + } + } + + const handleImageDelete = async () => { + setIsImageLoading(true) + + try { + const response = await fetch('/api/user/profile-image', { + method: 'DELETE', + }) + + const result = await response.json() + + if (!response.ok) { + toast.error(result.error || 'Failed to delete image') + return + } + + setProfileImageUrl(null) + toast.success('Profile image deleted successfully!') + + // Update session to remove image + await update({ + image: null + }) + + } catch (error) { + toast.error('An unexpected error occurred') + } finally { + setIsImageLoading(false) + } + } + + if (status === "loading") { + return ( +
+
+
+

Loading...

+
+
+ ) + } + + if (!session) { + return null + } + + return ( +
+ + +
+
+
+

Account Settings

+

+ Manage your account information and security settings +

+
+ + + + {/* Profile Information */} + + + + + Profile Information + + + Update your personal information + + + +
+ + ( + + Full Name + + + + + + )} + /> + ( + + Email Address + + + + + + )} + /> + + + +
+
+ + + + {/* Profile Image */} + + + + + Profile Image + + + Upload or update your profile picture + + + +
+ + + + {session?.user?.name?.charAt(0)?.toUpperCase() || 'U'} + + + +
+
+ + + {profileImageUrl && ( + + )} +
+ +

+ Supported formats: JPEG, PNG, WebP, GIF. Maximum size: 10MB. + Images will be resized to 400x400 pixels. +

+ + +
+
+
+
+ + + + {/* Password Change */} + + + + + Change Password + + + Update your password to keep your account secure + + + +
+ + ( + + Current Password + +
+ + +
+
+ +
+ )} + /> + ( + + New Password + +
+ + +
+
+ +
+ )} + /> + ( + + Confirm New Password + +
+ + +
+
+ +
+ )} + /> +
+ Password must contain at least 8 characters with uppercase, lowercase, and a number. +
+ + + +
+
+
+
+
+ ) +} \ No newline at end of file diff --git a/src/app/signup/page.tsx b/src/app/signup/page.tsx new file mode 100644 index 0000000..ab5b4d4 --- /dev/null +++ b/src/app/signup/page.tsx @@ -0,0 +1,208 @@ +"use client" + +import { useState } from "react" +import { useRouter } from "next/navigation" +import { zodResolver } from "@hookform/resolvers/zod" +import { useForm } from "react-hook-form" +import { Eye, EyeOff, Loader2, CheckCircle } from "lucide-react" +import Link from "next/link" + +import { Button } from "@/components/ui/button" +import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" +import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form" +import { Input } from "@/components/ui/input" +import { Alert, AlertDescription } from "@/components/ui/alert" + +import { registerSchema, type RegisterInput } from "@/lib/validation" + +export default function SignUpPage() { + const [showPassword, setShowPassword] = useState(false) + const [isLoading, setIsLoading] = useState(false) + const [error, setError] = useState("") + const [success, setSuccess] = useState(false) + const router = useRouter() + + const form = useForm({ + resolver: zodResolver(registerSchema), + defaultValues: { + name: "", + email: "", + password: "", + }, + }) + + const onSubmit = async (data: RegisterInput) => { + setIsLoading(true) + setError("") + setSuccess(false) + + try { + const response = await fetch("/api/auth/register", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(data), + }) + + const result = await response.json() + + if (!response.ok) { + setError(result.error || "Registration failed") + return + } + + setSuccess(true) + form.reset() + + // Redirect to login page after successful registration + setTimeout(() => { + router.push("/login") + }, 2000) + + } catch (error) { + setError("An unexpected error occurred") + } finally { + setIsLoading(false) + } + } + + if (success) { + return ( +
+ + + +
+

Account Created!

+

+ Your account has been successfully created. You will be redirected to the sign in page. +

+
+ +
+
+
+ ) + } + + return ( +
+ + + Create Account + + Enter your information to create a new account + + + + {error && ( + + {error} + + )} + +
+ + ( + + Full Name + + + + + + )} + /> + ( + + Email + + + + + + )} + /> + ( + + Password + +
+ + +
+
+ +

+ Password must contain at least 8 characters with uppercase, lowercase, and a number. +

+
+ )} + /> + + + + +
+ Already have an account? + + Sign in + +
+ +
+

+ By creating an account, you agree to our{" "} + {" "} + and{" "} + +

+
+
+
+
+ ) +} \ No newline at end of file -- cgit v1.3.1