Skip to content

Commit 5ea5940

Browse files
fforbeckAlan Shaw
and
Alan Shaw
committed
fix(space-creator): check provision result before proceeding (#119)
# Issue If the `NEXT_PUBLIC_W3UP_PROVIDER` environment variable is not set, the app will use `did:web:web3.storage` as the default storage provider. That works well if we are pointing to Prod environment (https://up.web3.storage), however, if we use the Staging environment (https://staging.up.web3.storage) it will fail to provision the space because the default provider is invalid for Staging. # Fix - Verify if the Space Provisioning result contains an error. If so, throw the error to prevent the user from continuing the flow and attempting to upload files. - Updated Docs and sample Env Vars. --------- Co-authored-by: Alan Shaw <[email protected]>
1 parent d0a2208 commit 5ea5940

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

.env.tpl

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# set these to your upload API service URL and the DID your service is using as its service DID
22
NEXT_PUBLIC_W3UP_SERVICE_URL=https://staging.up.web3.storage
33
NEXT_PUBLIC_W3UP_SERVICE_DID=did:web:staging.web3.storage
4+
NEXT_PUBLIC_W3UP_PROVIDER=did:web:staging.web3.storage
45

56
# set these to values from Stripe settings
67
NEXT_PUBLIC_STRIPE_PRICING_TABLE_ID=prctbl_1OCeiEF6A5ufQX5vPFlWRkPm

README.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,16 @@ You can start editing the page by modifying `app/page.tsx`. The page auto-update
2020

2121
### Using an alternate w3up service
2222

23-
By default, this app connects to https://up.web3.storage. To use an alternate service, specify
24-
the service URL and DID in your environment variables, like:
23+
By default, this app connects to `https://up.web3.storage`, and uses `did:web:web3.storage` as provider. To use an alternate service and/or provider, specify the service URL, service DID and provider DID in your environment variables, like so:
2524

2625
```
2726
NEXT_PUBLIC_W3UP_SERVICE_URL=https://your.w3up.service
2827
NEXT_PUBLIC_W3UP_SERVICE_DID=did:your-service-did
28+
NEXT_PUBLIC_W3UP_PROVIDER=did:your-provider-did
2929
```
3030

3131
An example `.env.local` file can be found in `.env.tpl`.
3232

3333
If you are using `w3infra`, the service URL will be displayed as the `UploadApiStack`'s `ApiEndpoint` output once `npm start` has successfully set up your development environment.
3434

3535
<p style="text-align:center;padding-top:2rem">⁂</p>
36-
37-

src/components/SpaceCreator.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ export function SpaceCreatorForm ({
5353
const space = await client.createSpace(name)
5454

5555
const provider = (process.env.NEXT_PUBLIC_W3UP_PROVIDER || 'did:web:web3.storage') as DID<'web'>
56-
await account.provision(space.did(), { provider })
56+
const result = await account.provision(space.did(), { provider })
57+
if (result.error) {
58+
setSubmitted(false)
59+
setCreated(false)
60+
throw new Error(`failed provisioning space: ${space.did()} with provider: ${provider}`, { cause: result.error })
61+
}
5762

5863
// MUST do this before creating recovery, as it creates necessary authorizations
5964
await space.save()

0 commit comments

Comments
 (0)