Authenticate a Space

First, authenticate a user's space.

To interact with a user's space, call box.openSpace().

If the user already has a space with this name, your application will gain access to it; if the user does not have the space, this method will automatically create one for them.

const space = await box.openSpace('myApp')

When called, this method will cause your user's Ethereum wallet provider to present the user with a message to sign: Allow this app to open your myApp space. It will look something like this:

Once approved, you will be able to update, decrypt, and interact with your user's space.

Want to authenticate multiple spaces? You will need to request each space authentication individually, and the user will need to approve each request individually in their wallet.

Then, sync data from the network.

When you first authenticate the user's space, all data might not be synced from the network yet. Therefore, you should wait for the data to be synced using the space.syncDone property. This will allow you to know when the user's current data is available to you.

await space.syncDone

We advise against setting any data before this sync has happened. However, reading data before the sync is complete is fine and encouraged - just remember to check for updates once this callback is fired!