2.1 KiB
2.1 KiB
React File Upload with Auth0 Authentication
A simple React application that allows users to upload files to a third-party API with Auth0 authentication.
Setup Instructions
-
Install dependencies:
npm install -
Configure Auth0:
- Create an account at Auth0
- Create a new application (Single Page Application)
- Update the following values in
src/main.jsx:domain: Your Auth0 domainclientId: Your Auth0 client IDaudience: Your API identifier (if applicable)
-
Update the API endpoint:
- In
src/App.jsx, update the/api/uploadendpoint to your actual third-party API endpoint
- In
-
Run the development server:
npm run dev
Deployment
-
Build for production:
npm run buildThis command generates the static files in the
dist/directory. -
Deploy to AWS S3 Static Website:
- Install AWS CLI if not already installed.
- Configure AWS CLI with your credentials:
aws configure - Create an S3 bucket for static hosting (e.g.,
s3://your-bucket-name):aws s3 mb s3://your-bucket-name - Enable static website hosting on the bucket.
- Upload the built files from the
dist/directory:aws s3 sync dist/ s3://your-bucket-name --delete - Set bucket policy for public read access (if needed).
- Your app will be available at the S3 static website endpoint.
Features
- Auth0 authentication (login/logout)
- File selection
- Secure file upload to third-party API with Bearer token
- Upload status feedback
How It Works
- Users log in with Auth0
- After authentication, users can select a file to upload
- When uploading, the app requests an access token from Auth0
- The file is sent to the third-party API with the access token in the Authorization header
- Upload status is displayed to the user
Customization
- Modify the
audienceandscopeinsrc/App.jsxbased on your API requirements - Update the file upload endpoint in the
handleUploadfunction - Customize the UI components as needed