@christonn93/react_template v0.0.1
š Project Name
A brief and clear description of your project.
(Optional: Add a screenshot of your app)
š Features
- ā Feature 1: Short description
- ā Feature 2: Short description
- ā Feature 3: Short description
š¦ Tech Stack
Technology | Description |
---|---|
React | Frontend library |
Vite | Fast build tool |
TypeScript | Strict typing for JavaScript |
MUI | UI component library |
Redux Toolkit (optional) | State management |
React Router | Client-side routing |
š ļø Installation
Clone the repository
git clone https://github.com/your-username/your-repo.git cd your-repo
Install dependencies
npm install
Start the development server
npm run dev
Build for production
npm run build
Run tests
npm run test
š Folder Structure
š¦ project-root
š¦ project-root
āāā š public # Public assets served by the web server (favicon, logo, etc.)
ā āāā favicon.ico # Favicon displayed in the browser tab
ā āāā logo.png # Logo image used in the app
ā āāā manifest.json # Web app manifest for PWA support
āāā š src
ā āāā š assets # Static assets like images, fonts, and global styles
ā āāā š components # Reusable UI components (buttons, forms, etc.)
ā āāā š config # Configuration files (e.g., API URLs, environment settings)
ā āāā š context # React context for managing app-wide state (e.g., user authentication)
ā āāā š features # Feature-specific logic (e.g., dashboard, user management)
ā āāā š hooks # Custom React hooks (e.g., useAuth, useLocalStorage)
ā ā āāā š handlers # Functions for handling specific operations (e.g., form submissions)
ā ā āāā š helpers # Helper functions for common tasks (e.g., formatDate)
ā ā āāā š query # Custom hooks for data fetching (e.g., useFetchData)
ā ā āāā š store # Zustand or Redux stores for managing state
ā ā āāā š utils # Utility functions for various operations (e.g., logging, validation)
ā āāā š layouts # Layout components for page structure (e.g., Header, Sidebar)
ā āāā š pages # Full-page components (e.g., HomePage, LoginPage)
ā āāā š providers # React context providers for app-wide state management
ā āāā š routes # Routing setup using React Router (e.g., Routes configuration)
ā āāā š services # API call functions (e.g., Axios or fetch API calls)
ā āāā š utils # Helper functions for general-purpose use across the app
ā ā āāā š Logger # Logger utilities for debugging and monitoring
ā āāā App.tsx # Main React component that renders the app
ā āāā main.tsx # Entry point for React app initialization
ā āāā index.css # Global styles (e.g., reset, typography)
āāā š tests # Test files (unit and integration tests)
ā āāā š unit # Unit tests for individual functions/components (vitest)
ā āāā š e2e # End-to-end tests (e.g., Cypress or Playwright)
āāā .eslintrc.cjs # ESLint configuration file
āāā .prettierrc # Prettier configuration file
āāā .gitignore # Git ignore rules to exclude unnecessary files
āāā package.json # Project dependencies and npm scripts
āāā tsconfig.json # TypeScript configuration
āāā vite.config.ts # Vite configuration file for bundling and development server
āāā README.md # Project documentation and instructions
š Environment Variables
Create a .env
file in the project root and add:
VITE_API_URL=http://localhost:3000
VITE_AUTH0_DOMAIN=your-auth0-domain
VITE_AUTH0_SCOPE=read:current_user
VITE_AUTH0_CLIENT_ID=your-auth0-client-id
VITE_AUTH0_AUDIENCE=your-auth0-audience
VITE_AUTH0_REDIRECT_URI=http://localhost:3000
VITE_AUTH0_LOGOUT_REDIRECT_URI=http://localhost:3000
VITE_AUTH0_ISSUER_BASE_URL=https://your-auth0-domain
VITE_AUTH0_COOKIE_DOMAIN=localhost
Variable | Description |
---|---|
VITE_API_URL | API endpoint for backend |
VITE_AUTH0_DOMAIN | Auth0 domain for your tenant |
VITE_AUTH0_SCOPE | Auth0 scope for authentication |
VITE_AUTH0_CLIENT_ID | Auth0 client ID for your app |
VITE_AUTH0_AUDIENCE | Auth0 audience URL for your app |
VITE_AUTH0_REDIRECT_URI | URL to redirect after successful login |
VITE_AUTH0_LOGOUT_REDIRECT_URI | URL to redirect after logout |
VITE_AUTH0_ISSUER_BASE_URL | Auth0 issuer base URL |
VITE_AUTH0_COOKIE_DOMAIN | Domain for setting Auth0 cookies |
š ļø Auth0 Configuration
Below is the authConfig
object, which sets up the Auth0 configuration in your app:
import { name, version } from '../../package.json';
export const authConfig = {
domain: import.meta.env.VITE_AUTH0_DOMAIN as string,
clientId: import.meta.env.VITE_AUTH0_CLIENT_ID as string,
audience: import.meta.env.VITE_AUTH0_AUDIENCE as string,
redirectUri: import.meta.env.VITE_AUTH0_REDIRECT_URI as string,
scope: import.meta.env.VITE_AUTH0_SCOPE as string,
authorizationParams: {
redirect_uri: import.meta.env.VITE_AUTH0_REDIRECT_URI as string,
},
auth0Client: {
name: name,
version: version,
env: {
NODE_ENV: import.meta.env.MODE, // to track environment (e.g., 'development', 'production')
},
},
authorizeTimeoutInSeconds: 60, // Timeout for authorization process
cacheLocation: 'localstorage' as const, // Cache location can be 'localstorage' or 'sessionstorage'
cookieDomain: import.meta.env.VITE_AUTH0_COOKIE_DOMAIN as string, // Set the domain for cookies
httpTimeoutInSeconds: 30, // Timeout for HTTP requests to Auth0
issuer: import.meta.env.VITE_AUTH0_ISSUER_BASE_URL as string, // Optional, issuer URL
leeway: 60, // Time in seconds to account for clock skew during token validation
legacySameSiteCookie: true, // Option for legacy SameSite cookie behavior
onRedirectCallback: () => {
// Optional callback after redirect
window.history.replaceState({}, document.title, window.location.pathname);
},
sessionCheckExpiryDays: 7, // Number of days before session expiry
skipRedirectCallback: false, // Skip redirect callback if needed
useCookiesForTransactions: true, // Use cookies for transactions
useFormData: true, // Use FormData for submission (for some environments)
useRefreshTokens: true, // Use refresh tokens to renew access tokens
useRefreshTokensFallback: false, // Fallback to another method if refresh tokens aren't available
workerUrl: '/worker.js', // URL for background workers (if needed)
};
Setting | Description |
---|---|
domain | Auth0 domain for your tenant |
clientId | Auth0 client ID for your app |
audience | Auth0 audience URL for your app |
redirectUri | URL to redirect after successful login |
scope | Scope for the authentication |
authorizationParams | Parameters for authorization redirection |
auth0Client | Client details including name, version, and environment |
authorizeTimeoutInSeconds | Timeout in seconds for authorization process |
cacheLocation | Where to store tokens (localstorage or sessionstorage ) |
cookieDomain | Domain for setting cookies |
httpTimeoutInSeconds | Timeout for HTTP requests to Auth0 |
issuer | Issuer URL for token validation |
leeway | Account for clock skew during token validation |
legacySameSiteCookie | Enable legacy SameSite cookie behavior |
onRedirectCallback | Optional callback after redirect |
sessionCheckExpiryDays | Days before session expiry |
skipRedirectCallback | Skip redirect callback if needed |
useCookiesForTransactions | Use cookies for transactions |
useFormData | Use FormData for submissions |
useRefreshTokens | Enable refresh tokens for renewing access tokens |
useRefreshTokensFallback | Use fallback method if refresh tokens aren't available |
workerUrl | URL for background workers (if needed) |
This formatting aligns with the example you've provided while clearly presenting the Auth0 configuration and environment variables.
Key Settings
redirectUri
andlogoutRedirectUri
: Defines where users are redirected after login or logout.cacheLocation
: The location to store tokens (eitherlocalstorage
orsessionstorage
).useRefreshTokens
: Enables the use of refresh tokens to renew access tokens.sessionCheckExpiryDays
: Specifies how many days before a session expires.
Ensure that you replace the placeholder values with your actual Auth0 information (domain, client ID, etc.) to enable seamless authentication in your application.
š Scripts
Command | Description |
---|---|
npm run dev | Start the development server |
npm run build | Build for production |
npm run preview | Preview production build |
npm run test | Run tests |
npm run lint | Check code quality |
š Contributing
- Fork the project
- Create a new branch:
git checkout -b feature-branch
- Commit your changes:
git commit -m "Add feature"
- Push to the branch:
git push origin feature-branch
- Create a Pull Request š
š License
This project is licensed under the MIT License.
See the LICENSE file for details.
š Contact
Your Name
āļø Email: your-email@example.com
š Website: your-website.com
8 months ago