0.0.1 • Published 8 months ago

@christonn93/react_template v0.0.1

Weekly downloads
-
License
-
Repository
-
Last release
8 months ago

šŸ“Œ Project Name

A brief and clear description of your project.

Project Screenshot (Optional: Add a screenshot of your app)


šŸš€ Features

  • āœ… Feature 1: Short description
  • āœ… Feature 2: Short description
  • āœ… Feature 3: Short description

šŸ“¦ Tech Stack

TechnologyDescription
ReactFrontend library
ViteFast build tool
TypeScriptStrict typing for JavaScript
MUIUI component library
Redux Toolkit (optional)State management
React RouterClient-side routing

šŸ› ļø Installation

  1. Clone the repository

    git clone https://github.com/your-username/your-repo.git
    cd your-repo
  2. Install dependencies

    npm install
  3. Start the development server

    npm run dev
  4. Build for production

    npm run build
  5. 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
VariableDescription
VITE_API_URLAPI endpoint for backend
VITE_AUTH0_DOMAINAuth0 domain for your tenant
VITE_AUTH0_SCOPEAuth0 scope for authentication
VITE_AUTH0_CLIENT_IDAuth0 client ID for your app
VITE_AUTH0_AUDIENCEAuth0 audience URL for your app
VITE_AUTH0_REDIRECT_URIURL to redirect after successful login
VITE_AUTH0_LOGOUT_REDIRECT_URIURL to redirect after logout
VITE_AUTH0_ISSUER_BASE_URLAuth0 issuer base URL
VITE_AUTH0_COOKIE_DOMAINDomain 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)
   };
SettingDescription
domainAuth0 domain for your tenant
clientIdAuth0 client ID for your app
audienceAuth0 audience URL for your app
redirectUriURL to redirect after successful login
scopeScope for the authentication
authorizationParamsParameters for authorization redirection
auth0ClientClient details including name, version, and environment
authorizeTimeoutInSecondsTimeout in seconds for authorization process
cacheLocationWhere to store tokens (localstorage or sessionstorage)
cookieDomainDomain for setting cookies
httpTimeoutInSecondsTimeout for HTTP requests to Auth0
issuerIssuer URL for token validation
leewayAccount for clock skew during token validation
legacySameSiteCookieEnable legacy SameSite cookie behavior
onRedirectCallbackOptional callback after redirect
sessionCheckExpiryDaysDays before session expiry
skipRedirectCallbackSkip redirect callback if needed
useCookiesForTransactionsUse cookies for transactions
useFormDataUse FormData for submissions
useRefreshTokensEnable refresh tokens for renewing access tokens
useRefreshTokensFallbackUse fallback method if refresh tokens aren't available
workerUrlURL 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 and logoutRedirectUri: Defines where users are redirected after login or logout.
  • cacheLocation: The location to store tokens (either localstorage or sessionstorage).
  • 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

CommandDescription
npm run devStart the development server
npm run buildBuild for production
npm run previewPreview production build
npm run testRun tests
npm run lintCheck code quality

šŸ›  Contributing

  1. Fork the project
  2. Create a new branch: git checkout -b feature-branch
  3. Commit your changes: git commit -m "Add feature"
  4. Push to the branch: git push origin feature-branch
  5. 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