From e53d2e58d63e510fa96918d99d8a591a78538905 Mon Sep 17 00:00:00 2001 From: Parker Close Date: Wed, 14 Oct 2026 13:10:38 -0700 Subject: [PATCH 01/16] Navbar link to profile --- app/Navbar.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Navbar.tsx b/app/Navbar.tsx index 317a24e..dce32b5 100644 --- a/app/Navbar.tsx +++ b/app/Navbar.tsx @@ -20,7 +20,7 @@ export default function Navbar({ session }: NavbarProps) { {session?.user ? ( <>
  • - {session.user.name ?? 'Member'} + {session.user.name ?? 'Member'}
  • Date: Wed, 14 Oct 2026 13:11:07 -0700 Subject: [PATCH 02/16] profile page base added --- app/profile/page.tsx | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 app/profile/page.tsx diff --git a/app/profile/page.tsx b/app/profile/page.tsx new file mode 100644 index 0000000..e816fc5 --- /dev/null +++ b/app/profile/page.tsx @@ -0,0 +1,20 @@ +import Link from 'next/link' + +type UserProps = { + session: { user?: { name?: string | null } } | null +} + +export default function ProfilePage({ session }: UserProps) { + return ( +
    +
    +
    + {/* profile image */} +

    {session?.user?.name}

    +

    +

    Quests created: {/*# of posts created by user*/}   Quests compeleted: {/*# of posts completed by user*/}

    +
    +
    +
    + ) +} \ No newline at end of file From 443317296b4e80615cc6d3f23d0f28276db3f6af Mon Sep 17 00:00:00 2001 From: Parker Close Date: Wed, 14 Oct 2026 13:32:33 -0700 Subject: [PATCH 03/16] user info now given to profile page --- app/profile/page.tsx | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/app/profile/page.tsx b/app/profile/page.tsx index e816fc5..a7c6c64 100644 --- a/app/profile/page.tsx +++ b/app/profile/page.tsx @@ -1,18 +1,29 @@ -import Link from 'next/link' +import { redirect } from 'next/navigation' +import { auth } from '../../auth' +import { prisma } from '../../lib/prisma' -type UserProps = { - session: { user?: { name?: string | null } } | null -} +export default async function ProfilePage() { + const session = await auth() + if (!session?.user?.email) { + redirect('/login') + } -export default function ProfilePage({ session }: UserProps) { + const user = await prisma.user.findUnique({ + where: { email: session.user.email }, + select: { + displayName: true, + createdAt: true, + }, + }) + return (
    {/* profile image */}

    {session?.user?.name}

    -

    -

    Quests created: {/*# of posts created by user*/}   Quests compeleted: {/*# of posts completed by user*/}

    +

    Member since: {user?.createdAt.toLocaleDateString()}

    +



    Quests created: {/*# of posts created by user*/}   Quests compeleted: {/*# of posts completed by user*/}

    From 8d85c6498b3453e578c3d776cf8a514be079b404 Mon Sep 17 00:00:00 2001 From: Parker Close Date: Wed, 14 Oct 2026 13:39:16 -0700 Subject: [PATCH 04/16] added redirect for login page --- app/login/actions.ts | 2 +- app/login/page.tsx | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/login/actions.ts b/app/login/actions.ts index 4c90b97..ba11440 100644 --- a/app/login/actions.ts +++ b/app/login/actions.ts @@ -29,7 +29,7 @@ export async function loginAction( } try { - await signIn('credentials', { ...credentials, redirectTo: '/' }) + await signIn('credentials', { ...credentials, redirectTo: '/posts' }) } catch (error) { if (error instanceof AuthError) { return { diff --git a/app/login/page.tsx b/app/login/page.tsx index ed7d4a3..dc1df8b 100644 --- a/app/login/page.tsx +++ b/app/login/page.tsx @@ -1,8 +1,14 @@ import Link from 'next/link' +import { redirect } from 'next/navigation' +import { auth } from '../../auth' import { LoginForm } from './LoginForm' -export default function LoginPage() { +export default async function LoginPage() { + const session = await auth() + if (!session?.user?.email) { + redirect('/') + } return (
    From e63e27532a1182186feed0e60a6c5fc97ffbfb45 Mon Sep 17 00:00:00 2001 From: Parker Close Date: Wed, 14 Oct 2026 13:43:18 -0700 Subject: [PATCH 05/16] fixed redirect --- app/login/page.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/login/page.tsx b/app/login/page.tsx index dc1df8b..780b24f 100644 --- a/app/login/page.tsx +++ b/app/login/page.tsx @@ -6,7 +6,7 @@ import { LoginForm } from './LoginForm' export default async function LoginPage() { const session = await auth() - if (!session?.user?.email) { + if (session?.user?.email) { redirect('/') } return ( From da3af0eb78139171f0f82f99654efaea58fee8cd Mon Sep 17 00:00:00 2001 From: Parker Close Date: Wed, 14 Oct 2026 13:43:31 -0700 Subject: [PATCH 06/16] added redirect for register page --- app/register/actions.ts | 2 +- app/register/page.tsx | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/register/actions.ts b/app/register/actions.ts index de0c056..c8539a5 100644 --- a/app/register/actions.ts +++ b/app/register/actions.ts @@ -68,7 +68,7 @@ export async function registerAction( } try { - await signIn('credentials', { email, password, redirectTo: '/' }) + await signIn('credentials', { email, password, redirectTo: '/posts' }) } catch (error) { if (error instanceof AuthError) { return { diff --git a/app/register/page.tsx b/app/register/page.tsx index 7e89410..1b45e9f 100644 --- a/app/register/page.tsx +++ b/app/register/page.tsx @@ -1,8 +1,14 @@ import Link from 'next/link' +import { redirect } from 'next/navigation' +import { auth } from '../../auth' import { RegisterForm } from './RegisterForm' -export default function RegisterPage() { +export default async function RegisterPage() { + const session = await auth() + if (session?.user?.email) { + redirect('/') + } return (
    From f9c2862911bb6b4e76185ffec96221a9eb1429b2 Mon Sep 17 00:00:00 2001 From: Parker Close Date: Tue, 20 Oct 2026 22:33:44 -0700 Subject: [PATCH 07/16] Profile settings - User can pick a profile image - User profile image shows up on Navbar --- .gitignore | 3 + app/Navbar.css | 22 ++ app/Navbar.tsx | 31 ++- app/api/profile/avatar/route.ts | 44 ++++ app/layout.tsx | 12 +- app/profile/ProfileSettings.tsx | 137 +++++++++++ app/profile/ProfileView.tsx | 112 +++++++++ app/profile/page.tsx | 61 +++-- app/profile/profile.module.css | 224 ++++++++++++++++++ lib/profile-images.ts | 58 +++++ .../migration.sql | 2 + prisma/schema.prisma | 1 + public/profile-images/.gitkeep | 0 public/profile-images/README.md | 8 + 14 files changed, 681 insertions(+), 34 deletions(-) create mode 100644 app/api/profile/avatar/route.ts create mode 100644 app/profile/ProfileSettings.tsx create mode 100644 app/profile/ProfileView.tsx create mode 100644 app/profile/profile.module.css create mode 100644 lib/profile-images.ts create mode 100644 prisma/migrations/20261020120000_add_user_avatar/migration.sql create mode 100644 public/profile-images/.gitkeep create mode 100644 public/profile-images/README.md diff --git a/.gitignore b/.gitignore index c55999a..b17ec00 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,6 @@ npm-debug.log* .DS_Store .idea/ .vscode/ + +# Windows download metadata +*:Zone.Identifier diff --git a/app/Navbar.css b/app/Navbar.css index aca85b9..70ee589 100644 --- a/app/Navbar.css +++ b/app/Navbar.css @@ -24,6 +24,28 @@ a:hover { text-decoration: underline; } +.navbar-profile { + display: inline-flex; + align-items: center; + gap: 0.5rem; +} + +.navbar-avatar { + display: inline-grid; + width: 2rem; + height: 2rem; + place-items: center; + overflow: hidden; + border-radius: 50%; + font-size: 1.25rem; +} + +.navbar-avatar img { + width: 100%; + height: 100%; + object-fit: cover; +} + nav form { margin: 0; } diff --git a/app/Navbar.tsx b/app/Navbar.tsx index dce32b5..3415e46 100644 --- a/app/Navbar.tsx +++ b/app/Navbar.tsx @@ -1,13 +1,16 @@ import Link from 'next/link' +import Image from 'next/image' import { signOut } from '../auth' +import type { ProfileImageOption } from '../lib/profile-images' import './Navbar.css' type NavbarProps = { session: { user?: { name?: string | null } } | null + avatar?: ProfileImageOption } -export default function Navbar({ session }: NavbarProps) { +export default function Navbar({ session, avatar }: NavbarProps) { return (
    { + const rawDisplayName = String(formData.get('displayName') ?? '') + const values = { displayName: rawDisplayName.trim() } + + try { + const session = await auth() + if (!session?.user?.email) { + return { + error: 'Please sign in again before updating your display name.', + success: '', + values, + } + } + + const displayName = validateDisplayName(rawDisplayName) + await prisma.user.update({ + where: { email: session.user.email }, + data: { displayName }, + }) + + return { + error: '', + success: 'Display name saved.', + values: { displayName }, + } + } catch (error) { + return { + error: + error instanceof Error && error.message.startsWith('Display name') + ? error.message + : 'We could not save your display name. Please try again.', + success: '', + values, + } + } +} diff --git a/app/profile/form-state.ts b/app/profile/form-state.ts new file mode 100644 index 0000000..ed739ad --- /dev/null +++ b/app/profile/form-state.ts @@ -0,0 +1,11 @@ +export type DisplayNameFormState = { + error: string + success: string + values: { displayName: string } +} + +export const initialDisplayNameFormState: DisplayNameFormState = { + error: '', + success: '', + values: { displayName: '' }, +} diff --git a/app/profile/page.tsx b/app/profile/page.tsx index 99854ae..a4dddd1 100644 --- a/app/profile/page.tsx +++ b/app/profile/page.tsx @@ -15,6 +15,7 @@ export default async function ProfilePage() { select: { avatarId: true, createdAt: true, + displayName: true, }, }) const imageOptions = await getProfileImageOptions() @@ -24,7 +25,7 @@ export default async function ProfilePage() { avatarId={user?.avatarId ?? imageOptions[0].id} imageOptions={imageOptions} memberSince={user?.createdAt} - name={session.user.name} + name={user?.displayName ?? session.user.name} /> ) } diff --git a/app/profile/profile.module.css b/app/profile/profile.module.css index cfc4cd1..9971e7f 100644 --- a/app/profile/profile.module.css +++ b/app/profile/profile.module.css @@ -142,6 +142,60 @@ font-size: 0.9rem; } +.nameForm { + display: flex; + gap: 0.75rem; + margin-top: 1rem; +} + +.nameForm input { + min-width: 0; + flex: 1; + min-height: 2.75rem; + padding: 0.5rem 0.75rem; + border: 1px solid var(--line); + color: var(--ink); + background: #fffdf8; + font: inherit; +} + +.nameForm button { + min-height: 2.75rem; + padding: 0.5rem 0.75rem; + border: 1px solid var(--accent); + color: var(--ink); + background: var(--accent-soft); + font: inherit; + font-weight: 700; + cursor: pointer; +} + +.nameForm input:focus-visible, +.nameForm button:focus-visible { + outline: 3px solid #236e69; + outline-offset: 3px; +} + +.nameForm button:disabled { + cursor: wait; + opacity: 0.65; +} + +.settingError { + margin-top: 0.75rem; + color: #6e2020; + font-size: 0.875rem; +} + +.visuallyHidden { + position: absolute; + width: 1px; + height: 1px; + overflow: hidden; + clip: rect(0 0 0 0); + white-space: nowrap; +} + .avatarGrid { display: grid; grid-template-columns: repeat(3, 1fr); diff --git a/lib/auth/validation.ts b/lib/auth/validation.ts index 144ddda..7120228 100644 --- a/lib/auth/validation.ts +++ b/lib/auth/validation.ts @@ -1,6 +1,18 @@ const registrationError = 'Please enter a display name, valid email address, and password of at least 8 characters.' +const displayNameError = 'Display name must be between 1 and 30 characters.' + +export function validateDisplayName(value: string): string { + const displayName = value.trim() + + if (displayName.length < 1 || displayName.length > 30) { + throw new Error(displayNameError) + } + + return displayName +} + export type RegistrationInput = { displayName: string email: string @@ -10,13 +22,16 @@ export type RegistrationInput = { export function validateRegistration( input: RegistrationInput, ): RegistrationInput { - const displayName = input.displayName.trim() + let displayName: string + try { + displayName = validateDisplayName(input.displayName) + } catch { + throw new Error(registrationError) + } const email = input.email.trim().toLowerCase() const password = input.password if ( - displayName.length < 1 || - displayName.length > 80 || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email) || email.length > 254 || password.length < 8 || diff --git a/tests/unit/display-name-validation.test.ts b/tests/unit/display-name-validation.test.ts new file mode 100644 index 0000000..c7eff55 --- /dev/null +++ b/tests/unit/display-name-validation.test.ts @@ -0,0 +1,16 @@ +import { describe, expect, it } from 'vitest' + +import { validateDisplayName } from '../../lib/auth/validation' + +describe('validateDisplayName', () => { + it('trims and accepts display names up to 30 characters', () => { + const displayName = validateDisplayName(' Community Garden Team Leaders! ') + + expect(displayName).toBe('Community Garden Team Leaders!') + expect(displayName).toHaveLength(30) + }) + + it('rejects display names longer than 30 characters', () => { + expect(() => validateDisplayName('a'.repeat(31))).toThrow() + }) +}) From 354ed2c9c8155cebd99bf41564de40b5dcac0b01 Mon Sep 17 00:00:00 2001 From: Parker Close Date: Tue, 20 Oct 2026 22:53:17 -0700 Subject: [PATCH 09/16] fixed navar alignment after adding profile image --- app/Navbar.css | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/Navbar.css b/app/Navbar.css index 70ee589..b75f27f 100644 --- a/app/Navbar.css +++ b/app/Navbar.css @@ -3,15 +3,18 @@ nav { color: black; } -ul { +nav > ul { list-style-type: none; margin: 1rem; padding: 0; display: flex; + align-items: center; justify-content: space-around; } -li { +nav > ul > li { + display: flex; + align-items: center; padding: 15px; } From aceaef6ee27b7257258432f11e998f0926a2c011 Mon Sep 17 00:00:00 2001 From: Parker Close Date: Sun, 25 Oct 2026 16:44:55 -0700 Subject: [PATCH 10/16] style changes --- app/profile/ProfileView.tsx | 9 +++++---- app/profile/profile.module.css | 35 +++++++++++++++++++++------------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/app/profile/ProfileView.tsx b/app/profile/ProfileView.tsx index b287404..97c40b9 100644 --- a/app/profile/ProfileView.tsx +++ b/app/profile/ProfileView.tsx @@ -81,23 +81,24 @@ export default function ProfileView({ )}
    -

    Your profile

    {name ?? 'SideCause member'}

    -

    +

    Member since: {memberSince?.toLocaleDateString() ?? 'Recently'}

    -

    Quests created: —   Quests completed: —

    +

    Quests created: --  
    Quests completed: --

    +

    Level: --   Total XP: --

    Date: Sun, 25 Oct 2026 18:37:37 -0700 Subject: [PATCH 11/16] Profile Page improvements - User can now set location and a description in settings - added section for where a users posts, and completed posts will go - stats box color changes with profile color - styling for mobile view --- app/profile/ProfileSettings.tsx | 85 +++++++- app/profile/ProfileView.tsx | 75 ++++++- app/profile/actions.ts | 57 ++++- app/profile/page.tsx | 4 + app/profile/profile-details-form-state.ts | 14 ++ app/profile/profile.module.css | 200 ++++++++++++++++-- lib/auth/validation.ts | 22 ++ .../migration.sql | 4 + prisma/schema.prisma | 2 + tests/unit/display-name-validation.test.ts | 28 ++- 10 files changed, 463 insertions(+), 28 deletions(-) create mode 100644 app/profile/profile-details-form-state.ts create mode 100644 prisma/migrations/20261025120000_add_profile_details/migration.sql diff --git a/app/profile/ProfileSettings.tsx b/app/profile/ProfileSettings.tsx index ee99896..5a76309 100644 --- a/app/profile/ProfileSettings.tsx +++ b/app/profile/ProfileSettings.tsx @@ -6,14 +6,24 @@ import { useRouter } from 'next/navigation' import type { ProfileImageOption } from '../../lib/profile-images' -import { updateDisplayNameAction } from './actions' +import { + updateDisplayNameAction, + updateProfileDetailsAction, +} from './actions' import { initialDisplayNameFormState } from './form-state' +import { initialProfileDetailsFormState } from './profile-details-form-state' import styles from './profile.module.css' type ProfileSettingsProps = { imageOptions: ProfileImageOption[] isOpen: boolean displayName: string + location: string + description: string + onProfileDetailsSaved: ( + location: string, + description: string, + ) => void onAvatarChange: (id: string) => void onClose: () => void saveState: 'idle' | 'saving' | 'saved' | 'error' @@ -24,6 +34,9 @@ export default function ProfileSettings({ imageOptions, isOpen, displayName, + location, + description, + onProfileDetailsSaved, onAvatarChange, onClose, saveState, @@ -36,6 +49,11 @@ export default function ProfileSettings({ ...initialDisplayNameFormState, values: { displayName }, }) + const [profileDetailsState, profileDetailsFormAction, isDetailsPending] = + useActionState(updateProfileDetailsAction, { + ...initialProfileDetailsFormState, + values: { description, location }, + }) useEffect(() => { if (!isOpen) return @@ -51,8 +69,23 @@ export default function ProfileSettings({ }, [isOpen, onClose]) useEffect(() => { - if (displayNameState.success) router.refresh() - }, [displayNameState.success, router]) + if (profileDetailsState.success) { + onProfileDetailsSaved( + profileDetailsState.values.location, + profileDetailsState.values.description, + ) + } + if (displayNameState.success || profileDetailsState.success) { + router.refresh() + } + }, [ + displayNameState.success, + onProfileDetailsSaved, + profileDetailsState.success, + profileDetailsState.values.description, + profileDetailsState.values.location, + router, + ]) if (!isOpen) return null @@ -81,6 +114,52 @@ export default function ProfileSettings({ +
    +
    +

    About you

    +

    + Share where you are and what you care about. +

    +
    +
    + + + +