TheDocumentation Index
Fetch the complete documentation index at: https://docs.mentraglass.com/llms.txt
Use this file to discover all available pages before exploring further.
@mentra/react library simplifies building React-based webviews that integrate seamlessly with MentraOS authentication. When users open your webview through the MentraOS Mobile App, they are automatically authenticated without requiring a separate login process.
What Are React Webviews?
React webviews are web applications built with React that run inside the MentraOS Mobile App. They provide rich user interfaces for:- Settings and Configuration: Let users customize your app’s behavior
- Data Visualization: Display charts, graphs, and analytics
- Content Management: Create, edit, and organize user content
- Dashboard Interfaces: Show personalized information and controls
@mentra/react library handles all the authentication complexity, automatically extracting and verifying user tokens from the MentraOS system.
Complete Example
There’s a complete example of a React webview in theMentraOS-React-Example-App repository. Simply follow along with the README to get off the ground quickly.
Installation
Install the React authentication library in your webview project:Prerequisites
- React 16.8+: The library uses React Hooks
- MentraOS App Server: Your backend must be deployed, either on the same domain as your frontend or on a different domain that allows CORS requests from your frontend.
- Developer Console Setup: Set the webview url in the developer console to your frontend server
Basic Setup
1. Wrap Your App with the Authentication Provider
TheMentraAuthProvider component manages authentication state for your entire React application:
2. Access Authentication State
Use theUseMentraAuth hook to access user information and authentication status:
Complete Example Application
Here’s a comprehensive example that demonstrates authentication, API calls, and error handling:Making Authenticated API Calls
ThefrontendToken from UseMentraAuth is a JWT token that you should include in the Authorization header when making requests to your App backend:
Authentication Hook API
TheUseMentraAuth hook returns an object with the following properties:
How Authentication Works
- Token Extraction: When the MentraOS Mobile App opens your webview, it appends an
aos_signed_user_tokenparameter to the URL - Token Verification: The library verifies the token’s signature against the MentraOS Cloud public key
- User Identification: If valid, it extracts the
userIdandfrontendTokenfrom the token payload - Persistence: The authentication data is stored in
localStoragefor the session - Context Sharing: All authentication state is made available through React Context
CORS Configuration
If your webview frontend is hosted separately from your app backend, configure CORS properly:Troubleshooting
Common Issues
“MentraOS signed user token not found”- Ensure your webview is opened through the MentraOS Mobile App
- Check that the manager app is correctly appending the token to your URL
- Verify your webview URL is configured correctly in the Developer Console
- Verify the device clock is synchronized (token expiration is time-sensitive)
- Check that you’re using the latest version of
@mentra/react - Ensure the MentraOS Mobile App is up to date
- Check that you’re sending the
Authorization: Bearer ${frontendToken}header - Verify your app server is configured to accept the frontend token
- Ensure CORS is configured properly if frontend and backend are on different domains
- Clear browser cache and localStorage
- Restart the MentraOS Mobile App
- Check browser developer tools for JavaScript errors
Debugging Tips
Enable debug logging to troubleshoot authentication issues:Next Steps
- Complete Example Application: See a complete example of a React webview
- Deploying a React App: This guide covers deploying the MentraOS React Example App to production
- Webview Authentication Overview: Learn about the broader authentication system
- Core Concepts: Understand the full MentraOS ecosystem

