JWT
JWT-based authentication
A React application with JWT-based authentication built with Vite, TypeScript, shadcn-ui, and Tailwind CSS.
Table of Contents
Quick Start
Prerequisites
Installation
Clone the repository:
Install dependencies:
Start the development server:
Access the application:
The app will be available at http://localhost:5173 (default Vite development server port)
Port 5173 is the default for Vite and can be customized in
vite.config.tsor via--portflagImportant: You need a valid JWT token to access the application
JWT Authentication
This application uses JWT (JSON Web Token) authentication with RS256 algorithm. Users must provide a valid JWT token to access the application.
How Authentication Works
Token-based Access: Users access the app by visiting:
http://localhost:5173?token=YOUR_JWT_TOKENToken Validation: The app validates the JWT using RSA public key cryptography
Session Storage: Valid tokens are stored locally for subsequent visits
Automatic Cleanup: The token parameter is removed from the URL after successful authentication
JWT Token Requirements
Your JWT token must:
Be signed with RS256 algorithm
Include the following claims:
sub(subject): User identifiername: User's display nameemail: User's email addressiat(issued at): Token creation timestampexp(expiry): Token expiration timestamp
Example JWT payload:
API Services
Text-to-Speech (TTS)
How it works: Text messages are sent to
/api/tts/endpoint with session ID and target languageWhat's sent: Response text, language preference (e.g.,
'mr','hi','en'), and session identifierResponse: Base64-encoded audio data that gets played back to the user
Automatic Speech Recognition (ASR)
How it works: Audio is captured from user's microphone, converted to base64, and sent to
/api/transcribe/What's sent: Base64-encoded audio data along with the service identifier, and the session identifier
Response: Transcribed text and detected language code for further processing
All API calls require JWT authentication via Bearer token in headers.
Demo Mode
Quick Demo Access with jwt.io
🚀 Want to try the app immediately? Use jwt.io to generate a demo token:
Go to jwt.io
Set the Algorithm to RS256
Use the demo public/private key pair:
Private Key (for signing):
Public Key (already configured in the app):
Set the payload with your user data:
Copy the generated JWT token from the left panel
Visit your app with the token:
Basic JWT Signing Instructions for jwt.io:
Paste your private key in the "Private Key" section (right panel)
Verify the public key appears automatically in the "Public Key" section
Edit the payload (middle section) with your desired claims
The encoded JWT will appear in the left panel — copy this token
Important: The signature will only be valid if the public/private key pair matches
Alternative Online JWT Tools
jwt.io — Most popular JWT debugger and generator
jwtbuilder.jamiekurtz.com — Simple JWT builder
token.dev — JWT generator with various algorithms
⚠️ IMPORTANT: The demo keys are for development only. DO NOT use them in production!
Production Setup
1. Generate Your Own RSA Key Pair
For production, you MUST generate your own RSA key pair using online tools:
Option 1: Using jwt.io
Go to jwt.io
Select RS256 algorithm
Click "Generate New Keys" at the bottom
Copy both the public and private keys
Option 2: Using Online Key Generators
cryptotools.net — RSA key pair generator
travistidwell.com — JSEncrypt key generator
8gwifi.org — RSA key generation tool
Option 3: Using OpenSSL (if available)
2. Update the Public Key
Replace the publicKeyPEM in src/contexts/AuthContext.tsx with your production public key:
3. Secure Your Private Key
Store your private key securely (environment variables, key vault, etc.)
Never commit private keys to version control
Use the private key in your authentication service to sign JWT tokens
4. Configure Your Authentication Service
Your authentication service should:
Validate user credentials (login, OAuth, etc.)
Generate JWT tokens using your private key and any JWT library
Redirect users to your app with the token:
https://your-app.com?token=${token}
You can test token generation using jwt.io with your production keys before implementing in your auth service.
Development
File Structure
Key Files
src/contexts/AuthContext.tsx: Main authentication logic with demo public keysrc/pages/ErrorPage.tsx: Handles authentication errors
Environment Variables
You can customize JWT settings and development server configuration via environment variables:
Testing Authentication
Generate a test token using jwt.io:
Use RS256 algorithm
Use the demo private key provided above
Set your desired payload
Test with the token:
Verify authentication:
Check browser console for JWT validation logs
Confirm user data appears in the application
Test token persistence across page refreshes
Technologies Used
Vite — Build tool and development server
React — UI framework
TypeScript — Type-safe JavaScript
shadcn-ui — UI component library
Tailwind CSS — Utility-first CSS framework
jose — JWT verification library
Security Considerations
Production Checklist
JWT Best Practices
Short expiration times: Use short-lived tokens (1–24 hours)
Refresh tokens: Implement refresh token rotation
Secure storage: Store tokens securely (httpOnly cookies preferred over localStorage)
Token validation: Always validate tokens server-side
Audience validation: Verify the
audclaim matches your application
Troubleshooting
Common Issues
1. "Authentication Required" Error
Ensure you have a valid JWT token
Check token expiration
Verify the public key matches your private key
2. JWT Verification Failed
Confirm token is signed with RS256 algorithm
Check that public key in
AuthContext.tsxis correctVerify token hasn't expired
3. Token Not Persisting
Check browser's localStorage for token data
Ensure token includes required claims (
sub,name,email)
Getting Help
Check browser console for detailed error messages
Verify JWT token at jwt.io
Review authentication logs in browser developer tools
Test with the demo keys provided in this README
Last updated