User Authentication
Relevant source files
The following files were used as context for generating this wiki page:The User Authentication system provides the entry point for players into the "Hold'em or Fold'em Poker" application. It handles both the registration of new users and the sign-in process for existing users. The current implementation is entirely client-side, featuring UI components for login and signup, form state management, and basic input validation.
Backend API interactions are currently simulated for demonstration purposes. A successful authentication event redirects the user to the main application page (/), where they can access features like the User Profile. The system is built with Next.js and React, utilizing useState for state management and useRouter for navigation.
Architecture
The authentication architecture is composed of page components that handle routing and dedicated form components that encapsulate the UI, logic, and state for signing in and signing up.
This diagram illustrates the relationship between the page routes and the UI components.
User Interface Components
The authentication flow is handled by two primary React components: LoginForm and SignupForm.
LoginForm
This component provides the user interface for existing users to sign in. It collects an email and password.
Key Features:
- Inputs for email and password.
- A "show/hide password" toggle for the password field.
- An error display area for feedback.
- A submit button that shows a loading state during the simulated API call.
- Links to the signup page (
/signup). - Placeholder buttons for social logins (Google, GitHub) and password reset, which are marked as "coming soon".
Sources: components/login-form.tsx
SignupForm
This component allows new users to create an account. It collects a name, email, and password.
Key Features:
- Inputs for name, email, password, and password confirmation.
- "Show/hide password" toggles for both password fields.
- Client-side validation for required fields, password matching, and password length.
- An error display area.
- A submit button with a loading state.
- A link to the login page (
/login).
Sources: components/signup-form.tsx
State Management
Both forms manage their state locally using the useState hook.
Login Form State
The LoginForm component uses the following state variables to manage the form's data and UI state.
| State Variable | Type | Description |
|---|---|---|
email | string | Stores the value of the email input field. |
password | string | Stores the value of the password input field. |
showPassword | boolean | Toggles the visibility of the password text. |
isLoading | boolean | Indicates if the form submission is in progress. |
error | string | Stores any error message to be displayed to the user. |
Sources: components/login-form.tsx:12-16
Signup Form State
The SignupForm component has a more extensive state to handle additional fields and validation.
| State Variable | Type | Description |
|---|---|---|
name | string | Stores the value of the name input field. |
email | string | Stores the value of the email input field. |
password | string | Stores the value of the password input field. |
confirmPassword | string | Stores the value of the confirm password field. |
showPassword | boolean | Toggles visibility for the main password field. |
showConfirmPassword | boolean | Toggles visibility for the confirm password field. |
isLoading | boolean | Indicates if the form submission is in progress. |
error | string | Stores any error message to be displayed. |
Sources: components/signup-form.tsx:11-19
Authentication Flows
The login and signup processes follow a similar client-side pattern involving user input, form submission, simulated API calls, and redirection.
Login Flow
The login process is initiated when a user submits their credentials. The system simulates an API call and redirects on success.
The following sequence diagram shows the login process.
Sources: components/login-form.tsx:19-32
An error is displayed if the email or password fields are empty.
Sources: components/login-form.tsx:26-29
Signup Flow
The signup flow includes client-side validation before the simulated API call.
Validation
Before submitting, the handleSubmit function in SignupForm performs several checks:
- All fields filled: Verifies that
name,email,password, andconfirmPasswordare not empty. - Passwords match: Ensures
passwordis identical toconfirmPassword. - Password length: Checks that the
passwordis at least 8 characters long.
If any of these checks fail, an error message is set and the submission is halted.
Sources: components/signup-form.tsx:25-40
Signup Sequence
This diagram shows the sequence of events for a successful user registration.
Sources: components/signup-form.tsx:22-47