This example demonstrates how to build a React-based webview for AugmentOS apps using the @augmentos/react
library. Check out the full AugmentOS React Documentation for more details.
- Node.js 18+ and Bun installed
- AugmentOS installed on your phone
- An AugmentOS Developer Console account
-
Create a new repo from this template using the
Use this template
dropdown in the upper right or the following command:gh repo create --template AugmentOS-Community/AugmentOS-React-Example-App
-
Clone your new repo locally:
git clone <your-repo-url>
-
cd into your repo, then type
bun install
-
Create a
.env
file by copying the example:
cp .env.example .env
Edit .env
with your app details:
PORT=3000
PACKAGE_NAME=com.yourname.reactexampleapp
AUGMENTOS_API_KEY=your_api_key_from_console
- Go to console.AugmentOS.org
- Click "Create App"
- Set your package name (must match
.env
) - Enter your public URL (later, update this to your ngrok URL)
- Add the MICROPHONE permission (required for transcriptions)
- Copy the API key to your
.env
file
For development with hot reload:
bun run dev
This starts:
- Backend server on port 3000
- React dev server on port 5173 (with proxy to backend)
ngrok http --url=<YOUR_NGROK_URL> 5173
┌─────────────────────┐
│ AugmentOS Manager │
│ App │
└──────────┬──────────┘
│ Opens webview with token
▼
┌─────────────────────┐
│ React Frontend │
│ (@augmentos/react) │
└──────────┬──────────┘
│ Authenticated SSE connection
▼
┌─────────────────────┐
│ Backend Server │
│ (@augmentos/sdk) │
└──────────┬──────────┘
│ Receives transcriptions
▼
┌─────────────────────┐
│ AugmentOS Session │
│ (Smart Glasses) │
└─────────────────────┘
- Authentication: The
AugmentosAuthProvider
automatically extracts and verifies the user token - SSE Connection: Establishes a Server-Sent Events connection to receive live updates
- UI Updates: Displays transcripts in real-time with connection status
- Session Management: Handles AugmentOS sessions when users activate the app
- Transcript Relay: Receives transcription events and forwards them via SSE
- Authentication: SDK middleware validates user tokens automatically
AugmentOS-React-Example-App/
├── src/
│ ├── index.ts # Backend server
│ └── frontend/
│ ├── main.tsx # React entry point
│ ├── App.tsx # Main app component
│ ├── components/
│ │ └── TranscriptDisplay.tsx
│ └── index.css # Tailwind CSS imports
├── index.html # Vite entry HTML
├── vite.config.ts # Vite configuration
├── tsconfig.json # TypeScript config
├── package.json # Dependencies
└── README.md # This file
Handles the SSE connection and displays live transcripts:
const TranscriptDisplay: React.FC = () => {
const { frontendToken } = useAugmentosAuth();
const [currentTranscript, setCurrentTranscript] = useState<string>('');
// ... SSE connection logic
};
Streams transcript updates to connected clients:
app.get('/api/transcripts', (req: AuthenticatedRequest, res) => {
// Set up SSE headers
res.writeHead(200, {
'Content-Type': 'text/event-stream',
// ...
});
// Stream updates
});
- Hot Reload: The frontend supports hot module replacement for instant updates
- Backend Changes: Backend changes require a restart (or use
bun --watch
) - Testing Auth: Test through the AugmentOS manager app for proper authentication
For production:
-
Build:
bun run build:prod
-
Run:
bun run start:prod
-
Deploy to your preferred hosting service. See DEPLOYMENT-single-server.md for more details.
- Ensure you're opening the webview from the AugmentOS manager app
- Check that your app URL in the Developer Console is correct
- Verify MICROPHONE permission is enabled in Developer Console
- Check the browser console for SSE connection errors
- Ensure you're speaking clearly near the device
- Check that your backend is running and accessible
- Verify CORS settings if frontend/backend are on different domains
- Look for authentication errors in backend logs