Docs : SDK : shareDatabase
shareDatabase lets you share a database with another user. Use this function to retrieve a token that any other user can use to open the database, or to share a database directly with another user.
Retrieving a share token:
userbase.shareDatabase({
databaseName: 'example-database-name'
}).then(({ shareToken }) => {
// Any other user can now open the database using this share token
}).catch((e) => console.error(e))
Sharing directly with another user:
userbase.shareDatabase({
databaseName: 'example-database-name',
username: 'alice'
}).then(() => {
// Alice can now access the database
}).catch((e) => console.error(e))
Parameters
-
databaseName [string] - The database name to share.
-
databaseId [string | optional] - The database to share's unique identifier. Can be used in place of databaseName.
-
username [string | optional] - The username to share the database with.
-
readOnly [boolean | optional] - Sets the recipient's access permissions to read only. Defaults to true.
-
requireVerified [boolean | optional] - If a username is provided, requires the user be verified via verifyUser. Defaults to true when a username is provided. This ensures the user is sharing the database directly with the expected user, and not a man-in-the-middle.
-
resharingAllowed [boolean | optional] - If a username is provided, sets the recipient's permissions to reshare the database. Defaults to false.
Result
-
shareToken [string | optional] - Any other user can pass this value to openDatabase. This is only returned when no username is provided as a parameter.
Notes
-
Be aware that the shareToken is sensitive. It can be used by anyone to access data stored in a database.
-
Each database can have two existing share tokens at a time - a read-only token, and a write token. Generating a new share token overwrites the existing share token that has the provided read/write permissions set.
-
To access a database that has been shared directly with a username, the recieving user can find the database's databaseId via getDatabases, and then provide that databaseId to openDatabase.
-
A user can verify another user via verifyUser at any point. Verifying a user after sharing a database directly with that user enables the verifier to make sure they shared the database with the expected user, and not a man-in-the-middle.
-
If a user deletes their account via deleteUser and they are the owner of a database, that database will be deleted even if it has been shared with other users.
Errors
- ParamsMustBeObject
- DatabaseNameMissing
- DatabaseNameMustBeString
- DatabaseNameCannotBeBlank
- DatabaseNameTooLong
- DatabaseNameRestricted
- DatabaseIdMustBeString
- DatabaseIdCannotBeBlank
- DatabaseIdInvalidLength
- DatabaseIdNotAllowed
- ShareTokenNotAllowed
- DatabaseNotFound
- UsernameCannotBeBlank
- UsernameMustBeString
- ReadOnlyMustBeBoolean
- ResharingAllowedMustBeBoolean
- ResharingNotAllowed
- ResharingWithWriteAccessNotAllowed
- RequireVerifiedMustBeBoolean
- SharingWithSelfNotAllowed
- UserNotSignedIn
- UserNotFound
- SubscriptionPlanNotSet
- SubscriptionNotFound
- SubscribedToIncorrectPlan
- SubscriptionInactive
- TrialExpired
- TooManyRequests
- ServiceUnavailable