Skip to content

Commit

Permalink
gateway authorization based on env
Browse files Browse the repository at this point in the history
  • Loading branch information
fforbeck committed Dec 20, 2024
1 parent 597240f commit 77679ad
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .env.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ NEXT_PUBLIC_W3UP_RECEIPTS_URL=https://staging.up.web3.storage/receipt/
NEXT_PUBLIC_W3UP_SERVICE_DID=did:web:staging.web3.storage
NEXT_PUBLIC_W3UP_PROVIDER=did:web:staging.web3.storage

# set these to your gateway service URL and DID
NEXT_PUBLIC_W3UP_GATEWAY_HOST=https://staging.freeway.dag.haus
NEXT_PUBLIC_W3UP_GATEWAY_ID=did:web:staging.w3s.link

# set these to values from Stripe settings
NEXT_PUBLIC_STRIPE_PRICING_TABLE_ID=prctbl_1OCeiEF6A5ufQX5vPFlWRkPm
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_51LO87hF6A5ufQX5viNsPTbuErzfavdrEFoBuaJJPfoIhzQXdOUdefwL70YewaXA32ZrSRbK4U4fqebC7SVtyeNcz00qmgNgueC
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/deploy-storacha.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ jobs:
echo "NEXT_PUBLIC_W3UP_SERVICE_URL=https://staging.up.storacha.network" >> .env
echo "NEXT_PUBLIC_W3UP_RECEIPTS_URL=https://staging.up.storacha.network/receipt/" >> .env
echo "NEXT_PUBLIC_W3UP_PROVIDER=did:web:staging.web3.storage" >> .env
echo "NEXT_PUBLIC_W3UP_GATEWAY_HOST=https://staging.freeway.dag.haus" >> .env
echo "NEXT_PUBLIC_W3UP_GATEWAY_ID=did:web:staging.w3s.link" >> .env
echo "NEXT_PUBLIC_STRIPE_PRICING_TABLE_ID=prctbl_1NzhdvF6A5ufQX5vKNZuRhie" >> .env
echo "NEXT_PUBLIC_STRIPE_TRIAL_PRICING_TABLE_ID=prctbl_1QIDHGF6A5ufQX5vOK9Xl8Up" >> .env
echo "NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_51LO87hF6A5ufQX5viNsPTbuErzfavdrEFoBuaJJPfoIhzQXdOUdefwL70YewaXA32ZrSRbK4U4fqebC7SVtyeNcz00qmgNgueC" >> .env
Expand Down Expand Up @@ -135,6 +137,8 @@ jobs:
echo "NEXT_PUBLIC_W3UP_SERVICE_URL=https://up.storacha.network" >> .env
echo "NEXT_PUBLIC_W3UP_RECEIPTS_URL=https://up.storacha.network/receipt/" >> .env
echo "NEXT_PUBLIC_W3UP_PROVIDER=did:web:web3.storage" >> .env
echo "NEXT_PUBLIC_W3UP_GATEWAY_HOST=https://freeway.dag.haus" >> .env
echo "NEXT_PUBLIC_W3UP_GATEWAY_ID=did:web:w3s.link" >> .env
echo "NEXT_PUBLIC_STRIPE_PRICING_TABLE_ID=prctbl_1OCJ1qF6A5ufQX5vM5DWg4rA" >> .env
echo "NEXT_PUBLIC_STRIPE_TRIAL_PRICING_TABLE_ID=prctbl_1QPYsuF6A5ufQX5vdIGAe54g" >> .env
echo "NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_live_51LO87hF6A5ufQX5vQTO5BHyz8y9ybJp4kg1GsBjYuqwluuwtQTkbeZzkoQweFQDlv7JaGjuIdUWAyuwXp3tmCfsM005lJK9aS8" >> .env
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ jobs:
echo "NEXT_PUBLIC_W3UP_SERVICE_URL=https://staging.up.web3.storage" >> .env
echo "NEXT_PUBLIC_W3UP_RECEIPTS_URL=https://staging.up.web3.storage/receipt/" >> .env
echo "NEXT_PUBLIC_W3UP_PROVIDER=did:web:staging.web3.storage" >> .env
echo "NEXT_PUBLIC_W3UP_GATEWAY_HOST=https://staging.freeway.dag.haus" >> .env
echo "NEXT_PUBLIC_W3UP_GATEWAY_ID=did:web:staging.w3s.link" >> .env
echo "NEXT_PUBLIC_STRIPE_PRICING_TABLE_ID=prctbl_1NzhdvF6A5ufQX5vKNZuRhie" >> .env
echo "NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_51LO87hF6A5ufQX5viNsPTbuErzfavdrEFoBuaJJPfoIhzQXdOUdefwL70YewaXA32ZrSRbK4U4fqebC7SVtyeNcz00qmgNgueC" >> .env
echo "NEXT_PUBLIC_STRIPE_CUSTOMER_PORTAL_LINK=https://billing.stripe.com/p/login/test_6oE29Gff99KO6mk8ww" >> .env
Expand Down Expand Up @@ -128,6 +130,8 @@ jobs:
echo "NEXT_PUBLIC_W3UP_SERVICE_URL=https://up.web3.storage" >> .env
echo "NEXT_PUBLIC_W3UP_RECEIPTS_URL=https://up.web3.storage/receipt/" >> .env
echo "NEXT_PUBLIC_W3UP_PROVIDER=did:web:web3.storage" >> .env
echo "NEXT_PUBLIC_W3UP_GATEWAY_HOST=https://freeway.dag.haus" >> .env
echo "NEXT_PUBLIC_W3UP_GATEWAY_ID=did:web:w3s.link" >> .env
echo "NEXT_PUBLIC_STRIPE_PRICING_TABLE_ID=prctbl_1OCJ1qF6A5ufQX5vM5DWg4rA" >> .env
echo "NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_live_51LO87hF6A5ufQX5vQTO5BHyz8y9ybJp4kg1GsBjYuqwluuwtQTkbeZzkoQweFQDlv7JaGjuIdUWAyuwXp3tmCfsM005lJK9aS8" >> .env
echo "NEXT_PUBLIC_STRIPE_CUSTOMER_PORTAL_LINK=https://billing.stripe.com/p/login/cN22aA62U6bO1sA9AA" >> .env
Expand Down
23 changes: 20 additions & 3 deletions src/components/SpaceCreator.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import type { ChangeEvent } from 'react'

import React, { useState } from 'react'
import { Space, useW3 } from '@w3ui/react'
import { ContentServeService, Space, useW3 } from '@w3ui/react'
import Loader from '../components/Loader'
import { DID, DIDKey } from '@ucanto/interface'
import { ConnectionView, DID, DIDKey } from '@ucanto/interface'
import { DidIcon } from './DidIcon'
import Link from 'next/link'
import { FolderPlusIcon, InformationCircleIcon } from '@heroicons/react/24/outline'
import Tooltip from './Tooltip'
import { H3 } from './Text'
import * as UcantoClient from '@ucanto/client'
import { HTTP } from '@ucanto/transport'
import * as CAR from '@ucanto/transport/car'

export function SpaceCreatorCreating(): JSX.Element {
return (
Expand Down Expand Up @@ -52,7 +55,21 @@ export function SpaceCreatorForm({

setSubmitted(true)
try {
const space = await client.createSpace(name)

const gatewayId = (process.env.NEXT_PUBLIC_W3UP_GATEWAY_ID || 'did:web:w3s.link') as DID<'web'>
const gatewayUrl = process.env.NEXT_PUBLIC_W3UP_GATEWAY_HOST || 'https://freeway.dag.haus' as string

const storachaGateway = UcantoClient.connect({
id: {
did: () => gatewayId
},
codec: CAR.outbound,
channel: HTTP.open({ url: new URL(gatewayUrl) }),
}) as ConnectionView<ContentServeService>

const space = await client.createSpace(name, {
authorizeGatewayServices: [storachaGateway]
})

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

0 comments on commit 77679ad

Please sign in to comment.