Skip to main content

Overview

PC Fix implements a robust authentication system that provides multiple login methods, secure password management, and seamless user session handling. The system uses JWT tokens for stateless authentication and supports both traditional email/password login and Google OAuth integration.

Authentication Methods

Email & Password Login

Users can create accounts and log in using their email address and password. Passwords are securely hashed using bcrypt with a salt factor of 10.
packages/api/src/modules/auth/auth.service.ts

Google OAuth Integration

For a frictionless login experience, PC Fix integrates with Google OAuth 2.0. Users can sign in with their Google account, and the system automatically creates a user profile if one doesn’t exist.
packages/api/src/modules/auth/auth.service.ts
The Google OAuth integration automatically creates a customer profile and sends a welcome email to new users.

JWT Token Management

Token Generation

JWT tokens are issued with a 7-day expiration period and include user ID, email, and role information.
packages/api/src/modules/auth/auth.service.ts

Token Storage

On the client side, authentication tokens are managed through Zustand state management:
packages/web/src/stores/authStore.ts

Password Reset Flow

Requesting Password Reset

Users who forget their password can request a reset link. The system generates a secure token that expires in 1 hour.
packages/api/src/modules/auth/auth.service.ts

Resetting Password

Users click the link in their email and submit a new password. The system verifies the token hasn’t expired before updating.
packages/api/src/modules/auth/auth.service.ts
Password reset tokens expire after 1 hour for security. Users must complete the reset process within this timeframe.

User Registration

New users can register with their personal information. The system automatically:
  • Hashes the password
  • Creates a customer profile
  • Sends a welcome email
  • Returns a JWT token for immediate login
packages/api/src/modules/auth/auth.service.ts

Password Management

Changing Password (Authenticated Users)

Logged-in users can change their password by providing their current password for verification:
packages/api/src/modules/auth/auth.service.ts

Account Deletion

Users can delete their accounts, but only if they don’t have active orders. This protects both the business and the customer:
packages/api/src/modules/auth/auth.service.ts

User Roles

The system supports two user roles defined in the database schema:
packages/api/prisma/schema.prisma
  • USER: Standard customers with access to shopping and order management
  • ADMIN: Administrators with access to the admin dashboard and management features

Security Features

Password Hashing

All passwords are hashed using bcrypt with a salt factor of 10 before storage

Token Expiration

JWT tokens expire after 7 days, requiring re-authentication for security

OAuth Security

Google OAuth tokens are verified server-side against Google’s API

Reset Token Expiry

Password reset tokens expire after 1 hour to prevent abuse

API Endpoints

Environment Variables

Required environment variables for authentication:
In development, JWT_SECRET defaults to ‘secret’, but you should always set a strong secret in production.