@portal-hq/firebase-storage package provides FirebaseStorage, a Portal Storage adapter that stores and retrieves backup encryption material using Firebase ID tokens. Requests are made to Portal’s token backup service (TBS); the Portal Client API key and Firebase ID token are sent so the backend can authenticate your app and the signed-in Firebase user, consistent with native iOS and Android Firebase backup behavior.
Installation
@react-native-firebase/auth) so getToken can obtain ID tokens for the current user.
The FirebaseStorage class
FirebaseStorage implements the Portal Storage contract from @portal-hq/utils. Portal injects its API client on the instance when you construct Portal (adapter.api = portal.api), which supplies the Client API key used in TBS requests.
Class definition
Constructor
FirebaseStorageOptions
| Property | Type | Required | Default | Description |
|---|---|---|---|---|
getToken | (options?: { forceRefresh?: boolean }) => Promise<string | null> | Yes | - | Returns a Firebase ID token for the signed-in user, or null if there is no user. Should call your Auth SDK’s token API (for example User#getIdToken). When options?.forceRefresh is true, request a refreshed token (used internally after a 401 from TBS). |
tbsHost | string | No | 'backup.web.portalhq.io' | Hostname or URL for the token backup service. Trailing slashes are stripped; localhost uses http, otherwise https is assumed if no scheme is present. |
The getToken callback
Portal invokes getToken before TBS traffic (including validateOperations). Implement it by delegating to Firebase Auth’s ID token API.
options.forceRefresh: Whentrue, obtain a new token from Firebase (for examplegetIdToken(true)). The adapter sets this on the retry path after an unauthorized (401) response so a stale token can be replaced.- Return
null: If there is no signed-in Firebase user, returnnull. Backup and recovery operations will fail until the user signs in and tokens are available.
X-Firebase-Token header together with the Portal Client API key (Authorization: Bearer … from the configured IPortalApi).
When no Firebase user is signed in
IfgetToken resolves to null, FirebaseStorage throws standard Error instances, including:
Firebase token is not available— Initial read/write/validate when no token could be obtained (for example nocurrentUser).Firebase token is not available. Ensure Firebase Auth is initialized and user is signed in.— FromvalidateOperations()when the token is missing.Firebase token refresh failed— After a401, the adapter retries once withgetToken({ forceRefresh: true }); if that still yieldsnull, this message is thrown.
Portal, you may also see Portal API not configured when api has not been set (normally Portal sets this for adapters listed under backup).
Other HTTP failures surface as messages such as Firebase account does not match this client (403), No encryption key found for Firebase backup method (404), TBS error <status>: …, or a timeout error if the request exceeds 30 seconds.
delete() is not supported for this method; calling it throws Firebase backups cannot be deleted.
Portal integration
Pass the adapter on thefirebase key of BackupOptions and use BackupMethods.Firebase with backupWallet and recoverWallet. For cloud-style Firebase backup, pass an empty ciphertext string for recoverWallet, matching other cloud backups in the React Native SDK.
Backup
Recovery
Related documentation
- @portal-hq/core —
Portal,BackupMethods,backupWallet,recoverWallet, andBackupOptions - Back up a wallet — Firebase Auth backup (product guide)
- React Native Firebase — Authentication