- Install next-auth@beta, bcryptjs, zod, and @auth/prisma-adapter - Create auth.ts with credentials provider and JWT session strategy - Create auth.config.ts for edge-compatible middleware configuration - Add NextAuth type extensions for session and JWT - Create API route handler for authentication - Configure environment variables for NextAuth - Add AUTH_SETUP.md documentation Task: 1. Set up authentication infrastructure Requirements: 1.1, 2.1
9.5 KiB
Requirements Document
Introduction
The User Authentication and Sharing feature extends the Ultimate Lists App to support multiple users with private lists and collaborative sharing capabilities. The system SHALL enable users to register accounts, authenticate securely, maintain private lists, and selectively share lists with other users through invitations. This feature transforms the application from a single-user task management tool into a multi-user collaborative platform while maintaining data privacy and security.
Glossary
- User: An individual with a registered account in the Ultimate Lists App
- Authentication: The process of verifying a user's identity through credentials
- Session: A period of authenticated access to the application
- Private List: A list that is only accessible to its owner and invited collaborators
- List Owner: The user who created a list and has full control over it
- Collaborator: A user who has been granted access to another user's list
- Invitation: A request sent by a list owner to grant another user access to a list
- Permission Level: The degree of access a user has to a list (owner, editor, viewer)
- Credential: User authentication information (email and password)
- Session Token: A secure identifier used to maintain authenticated sessions
Requirements
Requirement 1: User Registration
User Story: As a new user, I want to register for an account with my email and password, so that I can have my own private lists.
Acceptance Criteria
- WHEN a user submits a registration form with a valid email and password, THE Ultimate Lists App SHALL create a new user account with a unique identifier
- WHEN a user attempts to register with an email that already exists, THE Ultimate Lists App SHALL reject the registration and display an error message
- WHEN a user registers, THE Ultimate Lists App SHALL hash the password before storing it in the database
- WHEN a user completes registration, THE Ultimate Lists App SHALL create an authenticated session for that user
- WHEN a user provides a password during registration, THE Ultimate Lists App SHALL validate that the password meets minimum security requirements (at least 8 characters)
Requirement 2: User Authentication
User Story: As a registered user, I want to log in with my email and password, so that I can access my private lists.
Acceptance Criteria
- WHEN a user submits valid credentials, THE Ultimate Lists App SHALL authenticate the user and create a session
- WHEN a user submits invalid credentials, THE Ultimate Lists App SHALL reject the login attempt and display an error message
- WHEN a user logs in successfully, THE Ultimate Lists App SHALL redirect the user to their lists dashboard
- WHEN a user session expires, THE Ultimate Lists App SHALL require re-authentication before allowing access to protected resources
- WHEN a user logs out, THE Ultimate Lists App SHALL terminate the session and clear authentication tokens
Requirement 3: Session Management
User Story: As a logged-in user, I want my session to persist across page refreshes, so that I don't have to log in repeatedly.
Acceptance Criteria
- WHEN a user logs in, THE Ultimate Lists App SHALL create a secure session token
- WHEN a user refreshes the page, THE Ultimate Lists App SHALL validate the session token and maintain the authenticated state
- WHEN a session token is invalid or expired, THE Ultimate Lists App SHALL redirect the user to the login page
- WHEN a user closes the browser, THE Ultimate Lists App SHALL preserve the session for a configurable duration
- WHEN a user accesses a protected route without authentication, THE Ultimate Lists App SHALL redirect to the login page
Requirement 4: Private Lists
User Story: As a user, I want all my lists to be private by default, so that only I can see and modify them.
Acceptance Criteria
- WHEN a user creates a list, THE Ultimate Lists App SHALL associate the list with the user's account as the owner
- WHEN a user views their lists, THE Ultimate Lists App SHALL display only lists they own or have been granted access to
- WHEN a user attempts to access another user's private list without permission, THE Ultimate Lists App SHALL deny access and return an error
- WHEN a user queries for lists, THE Ultimate Lists App SHALL filter results to include only lists the user has permission to view
- WHEN a user deletes their account, THE Ultimate Lists App SHALL delete all lists owned by that user
Requirement 5: List Sharing and Invitations
User Story: As a list owner, I want to invite other users to collaborate on my lists, so that we can work together on shared tasks.
Acceptance Criteria
- WHEN a list owner invites a user by email, THE Ultimate Lists App SHALL create an invitation record with a unique identifier
- WHEN an invited user accepts an invitation, THE Ultimate Lists App SHALL grant the user access to the shared list
- WHEN an invited user declines an invitation, THE Ultimate Lists App SHALL remove the invitation record
- WHEN a list owner views a list, THE Ultimate Lists App SHALL display all users who have access to that list
- WHEN a list owner revokes a user's access, THE Ultimate Lists App SHALL remove the user's permission and prevent further access to the list
Requirement 6: Collaboration Permissions
User Story: As a list owner, I want to control what collaborators can do with my lists, so that I can maintain appropriate access levels.
Acceptance Criteria
- WHEN a list owner invites a collaborator, THE Ultimate Lists App SHALL allow the owner to specify a permission level (editor or viewer)
- WHEN a user with editor permission accesses a shared list, THE Ultimate Lists App SHALL allow the user to create, edit, and delete items
- WHEN a user with viewer permission accesses a shared list, THE Ultimate Lists App SHALL allow the user to view items but prevent modifications
- WHEN a user attempts an action beyond their permission level, THE Ultimate Lists App SHALL deny the action and display an error message
- WHEN a list owner changes a collaborator's permission level, THE Ultimate Lists App SHALL update the permission and enforce the new access level immediately
Requirement 7: User Profile Management
User Story: As a user, I want to manage my profile information, so that I can update my details and change my password.
Acceptance Criteria
- WHEN a user updates their profile information, THE Ultimate Lists App SHALL save the changes and associate them with the user's account
- WHEN a user changes their password, THE Ultimate Lists App SHALL validate the current password before allowing the change
- WHEN a user changes their password, THE Ultimate Lists App SHALL hash the new password before storing it
- WHEN a user updates their email address, THE Ultimate Lists App SHALL verify that the new email is not already in use
- WHEN a user views their profile, THE Ultimate Lists App SHALL display their current information without exposing sensitive data like password hashes
Requirement 8: Invitation Notifications
User Story: As an invited user, I want to be notified when someone shares a list with me, so that I can accept or decline the invitation.
Acceptance Criteria
- WHEN a user receives an invitation, THE Ultimate Lists App SHALL display the invitation in the user's notifications or invitations list
- WHEN a user views pending invitations, THE Ultimate Lists App SHALL display the list name and the inviter's information
- WHEN a user has pending invitations, THE Ultimate Lists App SHALL display a notification indicator
- WHEN a user accepts or declines an invitation, THE Ultimate Lists App SHALL remove it from the pending invitations list
- WHEN an invitation is created, THE Ultimate Lists App SHALL record the invitation timestamp
Requirement 9: Data Isolation and Security
User Story: As a user, I want my data to be secure and isolated from other users, so that my privacy is protected.
Acceptance Criteria
- WHEN the system queries for lists, THE Ultimate Lists App SHALL enforce user-based access control at the database query level
- WHEN the system queries for items, THE Ultimate Lists App SHALL ensure items are only returned if the user has access to the parent list
- WHEN a user attempts to access a resource, THE Ultimate Lists App SHALL verify the user's authentication before processing the request
- WHEN the system stores passwords, THE Ultimate Lists App SHALL use a secure hashing algorithm with salt
- WHEN the system creates session tokens, THE Ultimate Lists App SHALL generate cryptographically secure random tokens
Requirement 10: Migration of Existing Data
User Story: As an existing user of the app, I want my current lists to be preserved when the authentication system is added, so that I don't lose my data.
Acceptance Criteria
- WHEN the authentication system is deployed, THE Ultimate Lists App SHALL provide a migration path for existing anonymous lists
- WHEN an existing user registers for the first time, THE Ultimate Lists App SHALL associate any existing lists with the new user account
- WHEN lists are migrated to a user account, THE Ultimate Lists App SHALL preserve all list data including items, metadata, and timestamps
- WHEN the migration is complete, THE Ultimate Lists App SHALL ensure all lists have an associated owner
- WHEN a user accesses the app after migration, THE Ultimate Lists App SHALL display all their migrated lists in their account