This document describes the API key and login flow for the NeuronIP UI (login page, auth guard, token in localStorage). For session-based auth and cookies, see authentication-session.md; for API token usage and JWT, see api/authentication.md; for security mechanisms, see security/authentication.md.
NeuronIP uses API key-based authentication for accessing the platform. This document describes the authentication flow and how to use it.
The authentication system consists of:
- Login Page (
/login) - Where users enter their API key - Auth Guard - Protects dashboard routes and redirects unauthenticated users
- Token Management - Settings page allows users to update their API key
- Automatic Redirects - Seamless flow between authenticated and unauthenticated states
- User visits any dashboard route (e.g.,
/dashboard) AuthGuardchecks for API token inlocalStorage- If no token found, user is redirected to
/login - User enters their API key on the login page
- API key is validated against the backend
- If valid, token is stored in
localStorageand user is redirected to dashboard - If invalid, error message is shown
- If token exists in
localStorage, user can access all dashboard routes - Token is automatically included in all API requests via axios interceptor
- User can update their token in Settings → Security & Authentication
- User clicks logout in the header menu
- Token is cleared from
localStorage - User is redirected to
/login
A clean, centered login form that:
- Accepts API key input (password field)
- Validates the key against the backend before storing
- Shows loading state during validation
- Provides helpful information about creating API keys
- Automatically redirects authenticated users
A client-side component that:
- Wraps the dashboard layout
- Checks for API token on mount and route changes
- Redirects to
/loginif no token found - Shows loading state during check
- Skips check for
/loginroute
Enhanced settings component that:
- Shows current API key (masked)
- Allows updating the API key
- Validates new keys before saving
- Provides clear/remove functionality
- Shows validation status
API tokens are stored in browser localStorage with the key api_token:
localStorage.setItem('api_token', 'your-api-key-here')
localStorage.getItem('api_token')
localStorage.removeItem('api_token')The API client (/lib/api/client.ts) automatically includes the token in all requests:
apiClient.interceptors.request.use((config) => {
const token = localStorage.getItem('api_token')
if (token) {
config.headers.Authorization = `Bearer ${token}`
}
return config
})Users can create API keys using:
- API Endpoint:
POST /api/v1/auth/api-keys - CLI Script:
scripts/create-api-key.go - Database: Direct insert into
neuronip.api_keystable
- API keys are stored in
localStorage(client-side only) - Keys are never sent to third parties
- Keys are masked in the UI (only first 4 and last 4 characters shown)
- Keys are validated against the backend before being accepted
- Invalid keys are rejected with clear error messages
-
Clear your token:
localStorage.removeItem('api_token')
-
Visit any dashboard route:
http://localhost:3001/dashboard -
You should be redirected to:
http://localhost:3001/login -
Enter a valid API key and click "Sign In"
-
You should be redirected back to the dashboard
- Go to Settings → Security & Authentication
- You should see your current API key (masked)
- Click the eye icon to toggle visibility
- Enter a new API key and click "Update API Key"
- The key will be validated and saved if valid
- Click the user icon in the header
- Click "Logout"
- You should be redirected to
/login - Token should be cleared from
localStorage
- Verify the API key exists in the database
- Check that the key is not expired or revoked
- Ensure the backend API is running and accessible
- Check browser console for network errors
- Clear
localStoragecompletely - Check that
/loginroute is accessible - Verify
AuthGuardis not checking/loginroute
- Check browser's
localStoragesettings - Ensure cookies/localStorage are enabled
- Try in incognito/private mode to rule out extensions
Potential improvements:
- Session expiration and refresh tokens
- Remember me functionality
- OAuth/SSO integration
- Multi-factor authentication
- Token rotation policies
- API key scopes and permissions