This is a simple authentication example application using:
- Backend: FastAPI with Auth0 JWT validation
- Frontend: SolidJS with Auth0 authentication and Bootstrap styling
SampleApp/
├── .env.example # Example environment variables
├── backend/ # FastAPI backend
│ └── fastapi/ # FastAPI app
│ ├── auth.py # Auth0 JWT validation
│ ├── main.py # API endpoints
│ └── requirements.txt # Python dependencies
└── frontend/ # SolidJS frontend
└── solid-app/ # SolidJS application
├── src/ # Source code
│ ├── components/ # Components
│ │ ├── Auth.ts # Auth0 authentication
│ │ └── Protected.tsx # Protected component
│ ├── App.tsx # Main application
│ └── index.tsx # Entry point
└── package.json # Node.js dependencies
-
Navigate to the backend directory:
cd SampleApp/backend/fastapi -
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate -
Install dependencies:
pip install -r requirements.txt -
Following are the env file variables:
FRONTEND: VITE_AUTH0_DOMAIN, VITE_AUTH0_CLIENT_ID ,VITE_AUTH0_AUDIENCE BACKEND: AUTH0_DOMAIN, AUTH0_CLIENT_ID, AUTH0_API_AUDIENCE -
Run the FastAPI server:
uvicorn main:app --reloadThe API will be available at http://localhost:8000
-
Navigate to the frontend directory:
cd SampleApp/frontend/solid-app -
Install dependencies:
npm install -
Run the development server:
npm run devThe application will be available at http://localhost:5173
- Create an Auth0 account if you don't have one
- Create a new API in Auth0 dashboard
- Set the identifier to match your
AUTH0_API_AUDIENCEvalue
- Set the identifier to match your
- Create a new Single Page Application in Auth0 dashboard
- Set the allowed callback URLs to include your frontend URL (http://localhost:5173)
- Set the allowed logout URLs to include your frontend URL
- Set the allowed web origins to include your frontend URL
- Update the Auth0 configuration in the following files:
frontend/solid-app/src/components/Auth.ts- Update domain and clientId.envfile with the correct values
- User authentication with Auth0
- Protected API routes
- Responsive Bootstrap styling
- Error handling for authentication failures
- Token-based API access
You can run this project directly from terminal by the start.sh file in the main directory, or you can run separately for the frontend and the backend folder.
- Auth0 Login Issues: Ensure your Auth0 application has the correct callback URLs
- API Authentication Errors: Check that your Auth0 API audience and domain match in both frontend and backend
- CORS Errors: Ensure the
ALLOWED_ORIGINSin your .env file includes your frontend URL
This project is licensed under the MIT License.