Skip to content

Commit 77679ad

Browse files
committed
gateway authorization based on env
1 parent 597240f commit 77679ad

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

.env.tpl

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ NEXT_PUBLIC_W3UP_RECEIPTS_URL=https://staging.up.web3.storage/receipt/
44
NEXT_PUBLIC_W3UP_SERVICE_DID=did:web:staging.web3.storage
55
NEXT_PUBLIC_W3UP_PROVIDER=did:web:staging.web3.storage
66

7+
# set these to your gateway service URL and DID
8+
NEXT_PUBLIC_W3UP_GATEWAY_HOST=https://staging.freeway.dag.haus
9+
NEXT_PUBLIC_W3UP_GATEWAY_ID=did:web:staging.w3s.link
10+
711
# set these to values from Stripe settings
812
NEXT_PUBLIC_STRIPE_PRICING_TABLE_ID=prctbl_1OCeiEF6A5ufQX5vPFlWRkPm
913
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_51LO87hF6A5ufQX5viNsPTbuErzfavdrEFoBuaJJPfoIhzQXdOUdefwL70YewaXA32ZrSRbK4U4fqebC7SVtyeNcz00qmgNgueC

.github/workflows/deploy-storacha.yml

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ jobs:
4040
echo "NEXT_PUBLIC_W3UP_SERVICE_URL=https://staging.up.storacha.network" >> .env
4141
echo "NEXT_PUBLIC_W3UP_RECEIPTS_URL=https://staging.up.storacha.network/receipt/" >> .env
4242
echo "NEXT_PUBLIC_W3UP_PROVIDER=did:web:staging.web3.storage" >> .env
43+
echo "NEXT_PUBLIC_W3UP_GATEWAY_HOST=https://staging.freeway.dag.haus" >> .env
44+
echo "NEXT_PUBLIC_W3UP_GATEWAY_ID=did:web:staging.w3s.link" >> .env
4345
echo "NEXT_PUBLIC_STRIPE_PRICING_TABLE_ID=prctbl_1NzhdvF6A5ufQX5vKNZuRhie" >> .env
4446
echo "NEXT_PUBLIC_STRIPE_TRIAL_PRICING_TABLE_ID=prctbl_1QIDHGF6A5ufQX5vOK9Xl8Up" >> .env
4547
echo "NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_51LO87hF6A5ufQX5viNsPTbuErzfavdrEFoBuaJJPfoIhzQXdOUdefwL70YewaXA32ZrSRbK4U4fqebC7SVtyeNcz00qmgNgueC" >> .env
@@ -135,6 +137,8 @@ jobs:
135137
echo "NEXT_PUBLIC_W3UP_SERVICE_URL=https://up.storacha.network" >> .env
136138
echo "NEXT_PUBLIC_W3UP_RECEIPTS_URL=https://up.storacha.network/receipt/" >> .env
137139
echo "NEXT_PUBLIC_W3UP_PROVIDER=did:web:web3.storage" >> .env
140+
echo "NEXT_PUBLIC_W3UP_GATEWAY_HOST=https://freeway.dag.haus" >> .env
141+
echo "NEXT_PUBLIC_W3UP_GATEWAY_ID=did:web:w3s.link" >> .env
138142
echo "NEXT_PUBLIC_STRIPE_PRICING_TABLE_ID=prctbl_1OCJ1qF6A5ufQX5vM5DWg4rA" >> .env
139143
echo "NEXT_PUBLIC_STRIPE_TRIAL_PRICING_TABLE_ID=prctbl_1QPYsuF6A5ufQX5vdIGAe54g" >> .env
140144
echo "NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_live_51LO87hF6A5ufQX5vQTO5BHyz8y9ybJp4kg1GsBjYuqwluuwtQTkbeZzkoQweFQDlv7JaGjuIdUWAyuwXp3tmCfsM005lJK9aS8" >> .env

.github/workflows/deploy.yml

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ jobs:
4040
echo "NEXT_PUBLIC_W3UP_SERVICE_URL=https://staging.up.web3.storage" >> .env
4141
echo "NEXT_PUBLIC_W3UP_RECEIPTS_URL=https://staging.up.web3.storage/receipt/" >> .env
4242
echo "NEXT_PUBLIC_W3UP_PROVIDER=did:web:staging.web3.storage" >> .env
43+
echo "NEXT_PUBLIC_W3UP_GATEWAY_HOST=https://staging.freeway.dag.haus" >> .env
44+
echo "NEXT_PUBLIC_W3UP_GATEWAY_ID=did:web:staging.w3s.link" >> .env
4345
echo "NEXT_PUBLIC_STRIPE_PRICING_TABLE_ID=prctbl_1NzhdvF6A5ufQX5vKNZuRhie" >> .env
4446
echo "NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_51LO87hF6A5ufQX5viNsPTbuErzfavdrEFoBuaJJPfoIhzQXdOUdefwL70YewaXA32ZrSRbK4U4fqebC7SVtyeNcz00qmgNgueC" >> .env
4547
echo "NEXT_PUBLIC_STRIPE_CUSTOMER_PORTAL_LINK=https://billing.stripe.com/p/login/test_6oE29Gff99KO6mk8ww" >> .env
@@ -128,6 +130,8 @@ jobs:
128130
echo "NEXT_PUBLIC_W3UP_SERVICE_URL=https://up.web3.storage" >> .env
129131
echo "NEXT_PUBLIC_W3UP_RECEIPTS_URL=https://up.web3.storage/receipt/" >> .env
130132
echo "NEXT_PUBLIC_W3UP_PROVIDER=did:web:web3.storage" >> .env
133+
echo "NEXT_PUBLIC_W3UP_GATEWAY_HOST=https://freeway.dag.haus" >> .env
134+
echo "NEXT_PUBLIC_W3UP_GATEWAY_ID=did:web:w3s.link" >> .env
131135
echo "NEXT_PUBLIC_STRIPE_PRICING_TABLE_ID=prctbl_1OCJ1qF6A5ufQX5vM5DWg4rA" >> .env
132136
echo "NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_live_51LO87hF6A5ufQX5vQTO5BHyz8y9ybJp4kg1GsBjYuqwluuwtQTkbeZzkoQweFQDlv7JaGjuIdUWAyuwXp3tmCfsM005lJK9aS8" >> .env
133137
echo "NEXT_PUBLIC_STRIPE_CUSTOMER_PORTAL_LINK=https://billing.stripe.com/p/login/cN22aA62U6bO1sA9AA" >> .env

src/components/SpaceCreator.tsx

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import type { ChangeEvent } from 'react'
22

33
import React, { useState } from 'react'
4-
import { Space, useW3 } from '@w3ui/react'
4+
import { ContentServeService, Space, useW3 } from '@w3ui/react'
55
import Loader from '../components/Loader'
6-
import { DID, DIDKey } from '@ucanto/interface'
6+
import { ConnectionView, DID, DIDKey } from '@ucanto/interface'
77
import { DidIcon } from './DidIcon'
88
import Link from 'next/link'
99
import { FolderPlusIcon, InformationCircleIcon } from '@heroicons/react/24/outline'
1010
import Tooltip from './Tooltip'
1111
import { H3 } from './Text'
12+
import * as UcantoClient from '@ucanto/client'
13+
import { HTTP } from '@ucanto/transport'
14+
import * as CAR from '@ucanto/transport/car'
1215

1316
export function SpaceCreatorCreating(): JSX.Element {
1417
return (
@@ -52,7 +55,21 @@ export function SpaceCreatorForm({
5255

5356
setSubmitted(true)
5457
try {
55-
const space = await client.createSpace(name)
58+
59+
const gatewayId = (process.env.NEXT_PUBLIC_W3UP_GATEWAY_ID || 'did:web:w3s.link') as DID<'web'>
60+
const gatewayUrl = process.env.NEXT_PUBLIC_W3UP_GATEWAY_HOST || 'https://freeway.dag.haus' as string
61+
62+
const storachaGateway = UcantoClient.connect({
63+
id: {
64+
did: () => gatewayId
65+
},
66+
codec: CAR.outbound,
67+
channel: HTTP.open({ url: new URL(gatewayUrl) }),
68+
}) as ConnectionView<ContentServeService>
69+
70+
const space = await client.createSpace(name, {
71+
authorizeGatewayServices: [storachaGateway]
72+
})
5673

5774
const provider = (process.env.NEXT_PUBLIC_W3UP_PROVIDER || 'did:web:web3.storage') as DID<'web'>
5875
const result = await account.provision(space.did(), { provider })

0 commit comments

Comments
 (0)