diff --git a/scripts/generate-key.ts b/scripts/generate-key.ts index 4f7926d..223c575 100644 --- a/scripts/generate-key.ts +++ b/scripts/generate-key.ts @@ -1,9 +1,10 @@ import { generateClientAssertionKey } from '@atcute/oauth-node-client'; const key = await generateClientAssertionKey('main-key'); +const json = JSON.stringify(key); -console.log('Add this to your .dev.vars file:\n'); -console.log(`CLIENT_ASSERTION_KEY=${JSON.stringify(JSON.stringify(key))}`); -console.log('\nFor Cloudflare Workers, add it as a secret:'); -console.log('npx wrangler secret put CLIENT_ASSERTION_KEY'); -console.log('(paste the JSON value without the outer quotes)'); +console.log('Generated client assertion key.\n'); +console.log('Set it as a Cloudflare Workers secret:\n'); +console.log(' npx wrangler secret put CLIENT_ASSERTION_KEY\n'); +console.log('Then paste this value:\n'); +console.log(json); diff --git a/src/lib/atproto/settings.ts b/src/lib/atproto/settings.ts index 292d08a..719eace 100644 --- a/src/lib/atproto/settings.ts +++ b/src/lib/atproto/settings.ts @@ -1,6 +1,8 @@ import { dev } from '$app/environment'; -export const SITE = dev ? 'http://localhost:5183' : 'https://flo-bit.dev'; +export const SITE = dev + ? 'http://localhost:5183' + : 'https://svelte-atproto-oauth-cloudflare-workers.flobit-dev.workers.dev/'; type Permissions = { collections: readonly string[]; diff --git a/src/lib/server/oauth.ts b/src/lib/server/oauth.ts index 18a065f..1eb2bfa 100644 --- a/src/lib/server/oauth.ts +++ b/src/lib/server/oauth.ts @@ -72,7 +72,10 @@ export function createOAuthClient(env?: App.Platform['env']): OAuthClient { } // In production, use confidential client with keyset - const key: ClientAssertionPrivateJwk = JSON.parse(env!.CLIENT_ASSERTION_KEY); + if (!env?.CLIENT_ASSERTION_KEY) { + throw new Error('CLIENT_ASSERTION_KEY secret is not set. Run: pnpm generate-key && npx wrangler secret put CLIENT_ASSERTION_KEY'); + } + const key: ClientAssertionPrivateJwk = JSON.parse(env.CLIENT_ASSERTION_KEY); const SITE = 'https://flo-bit.dev'; return new OAuthClient({