Get the endpoint of DID Space when you first log in to the application.
Overview#
When you want your application to store each user's data in their own DID Space, you can require users to bind their DID Space during their first login through certain settings, authorizing your application to access the user's own DID Space.
Prerequisite#
- You already have your own space for debugging. If you don't have it yet, you can refer to https://www.arcblock.io/content/docs/did-spaces/zh/buy-a-did-space for access.
- Your application is configured with the value of
blocklet.yml#capabilities.didSpace
asrequiredOnConnect
.
Operation process#
Requesting users to present DID Space NFT.#
When the user first logs into your application, they must present their own DID Space NFT.
After successfully presenting the DID Space, users can click on Profile, then click on the Settings icon in the top right corner, and switch to the Storage tab to see the just connected DID Space.
The application reads the user's DID Space endpoint.#
At this point, when the application is running, you can obtain the user's DID Space endpoint through the following code:
const AuthService = require('@blocklet/sdk/service/auth');
const authService = new AuthService();
const { user } = await authService.getUser(userDid);
console.log(user.didSpace.endpoint);
// 输出形如: https://space.team.arcblock.io/app/api/space/zNKhe8jwgNZX2z7ZUfwNddNECxSe3wyg7VtS/app/zNKfEK9actwBeLhfVvc9U1p1CqVWxtivVxo6/object/
After obtaining the DID Space endpoint, you will be able to read and write data on DID Space, refer to: https://www.arcblock.io/docs/did-spaces/zh/24293819-b746-4ae1-89be-07e9477b04f9