useBasic
TheuseBasic hook is used to access authentication, database, and other Basic features.
Any of these properties can be accessed by destructuring the useBasic hook.
Auth State
isReady
Boolean that indicates when auth state has been determined. Use this as a loading state for your app while auth is being verified.
App.tsx
isAuthReady is a deprecated alias for isReady and will be removed in a future version.isSignedIn
Boolean that checks if a user is signed in. Only use after
isReady is true.App.tsx
user
The current user object containing the user’s ID, email, and name. Returns User type:
null when not signed in.App.tsx
Auth Methods
signIn
Function to sign a user in via the Basic OAuth flow. It will redirect the user to the Basic login page, and then redirect them back to the page they were on.
App.tsx
signin (lowercase) is a deprecated alias for signIn and will be removed in a future version.signOut
Function to sign a user out. User remains on your page after signing out, but
isSignedIn will be set to false until they sign in again.App.tsx
signout (lowercase) is a deprecated alias for signOut and will be removed in a future version.signInWithCode
Function to complete authentication using an OAuth authorization code. Useful for custom OAuth flows or React Native apps where you handle the redirect manually.AuthResult type:
App.tsx
getToken
Fetches the user’s JWT access token. The token is automatically refreshed if expired. Use this for making authenticated API calls to your own backend.
App.tsx
getSignInUrl
Returns the OAuth sign-in URL without redirecting. Useful for custom sign-in flows, React Native apps, or opening in a popup/modal.
App.tsx
getSignInLink is a deprecated alias for getSignInUrl and will be removed in a future version.Database
db
The database object, which you can use to read, add, update, and delete items.
dbStatus
The current status of the database connection. Possible values are:
-
'LOADING'- Database is initializing -
'CONNECTING'- Attempting to connect to sync server -
'ONLINE'- Connected and syncing -
'SYNCING'- Actively syncing data -
'OFFLINE'- No network connection (still works locally) -
'ERROR_WILL_RETRY'- Non-fatal error, will automatically retry -
'ERROR'- Fatal error occurredApp.tsx
dbMode
The current database mode. See Database Modes for details.
'sync'- Local-first with IndexedDB + real-time WebSocket sync (default)'remote'- Direct REST API calls to server
useQuery
TheuseQuery hook is used to “subscribe” to data from the database, so that your component automatically re-renders when the data changes. It enables real-time sync between the local database, users’ devices, and all other users connected to the same database.
useQuery only works in sync mode. In remote mode, use regular async/await patterns instead..get() and .getAll() functions, and it takes a function as an argument.
The default value is an empty array
[] while data is loading. This may change in a future version.
