[READ-ONLY] a fast, modern browser for the npm registry
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: support dynamic client URI for preview deployments (#739)

Co-authored-by: Daniel Roe <daniel@roe.dev>

authored by

Nandkishor Jadoun
Daniel Roe
and committed by
GitHub
d189f995 2ba9247e

+25 -4
+1 -1
knip.json
··· 36 36 "vite-plugin-pwa", 37 37 "vue-router" 38 38 ], 39 - "ignoreUnresolved": ["#components"] 39 + "ignoreUnresolved": ["#components", "#oauth/config"] 40 40 }, 41 41 "cli": { 42 42 "project": ["src/**/*.ts"]
+21 -1
modules/oauth.ts
··· 1 - import { defineNuxtModule, useNuxt } from 'nuxt/kit' 1 + import { defineNuxtModule, useNuxt, addServerTemplate } from 'nuxt/kit' 2 2 import { join } from 'node:path' 3 3 import { appendFileSync, existsSync, readFileSync } from 'node:fs' 4 4 import { randomUUID } from 'node:crypto' ··· 9 9 }, 10 10 setup() { 11 11 const nuxt = useNuxt() 12 + 13 + const env = process.env.NUXT_ENV_VERCEL_ENV 14 + const previewUrl = process.env.NUXT_ENV_VERCEL_URL 15 + const prodUrl = process.env.NUXT_ENV_VERCEL_PROJECT_PRODUCTION_URL 16 + 17 + let clientUri: string 18 + if (env === 'preview' && previewUrl) { 19 + clientUri = `https://${previewUrl}` 20 + } else if (env === 'production' && prodUrl) { 21 + clientUri = `https://${prodUrl}` 22 + } else { 23 + clientUri = 'http://127.0.0.1:3000' 24 + } 25 + 26 + // bake it into a virtual file 27 + addServerTemplate({ 28 + filename: '#oauth/config', 29 + getContents: () => `export const clientUri = ${JSON.stringify(clientUri)};`, 30 + }) 31 + 12 32 if (nuxt.options._prepare || process.env.NUXT_SESSION_PASSWORD) { 13 33 return 14 34 }
+3 -2
server/utils/atproto/oauth.ts
··· 6 6 import { useOAuthStorage } from '#server/utils/atproto/storage' 7 7 import { UNSET_NUXT_SESSION_PASSWORD } from '#shared/utils/constants' 8 8 import { OAuthMetadataSchema } from '#shared/schemas/oauth' 9 + // @ts-expect-error virtual file from oauth module 10 + import { clientUri } from '#oauth/config' 9 11 // TODO: limit scope as features gets added. atproto just allows login so no scary login screen till we have scopes 10 12 export const scope = 'atproto' 11 13 12 14 export function getOauthClientMetadata() { 13 15 const dev = import.meta.dev 14 16 15 - // on dev, match in nuxt.config.ts devServer: { host: "127.0.0.1" } 16 - const client_uri = dev ? `http://127.0.0.1:3000` : 'https://npmx.dev' 17 + const client_uri = clientUri 17 18 const redirect_uri = `${client_uri}/api/auth/atproto` 18 19 19 20 const client_id = dev