Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion knip.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"vite-plugin-pwa",
"vue-router"
],
"ignoreUnresolved": ["#components"]
"ignoreUnresolved": ["#components", "#oauth/config"]
},
"cli": {
"project": ["src/**/*.ts"]
Expand Down
22 changes: 21 additions & 1 deletion modules/oauth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineNuxtModule, useNuxt } from 'nuxt/kit'
import { defineNuxtModule, useNuxt, addServerTemplate } from 'nuxt/kit'
import { join } from 'node:path'
import { appendFileSync, existsSync, readFileSync } from 'node:fs'
import { randomUUID } from 'node:crypto'
Expand All @@ -9,6 +9,26 @@ export default defineNuxtModule({
},
setup() {
const nuxt = useNuxt()

const env = process.env.NUXT_ENV_VERCEL_ENV
const previewUrl = process.env.NUXT_ENV_VERCEL_URL
const prodUrl = process.env.NUXT_ENV_VERCEL_PROJECT_PRODUCTION_URL

let clientUri: string
if (env === 'preview' && previewUrl) {
clientUri = `https://${previewUrl}`
} else if (env === 'production' && prodUrl) {
clientUri = `https://${prodUrl}`
} else {
clientUri = 'http://127.0.0.1:3000'
}

// bake it into a virtual file
addServerTemplate({
filename: '#oauth/config',
getContents: () => `export const clientUri = ${JSON.stringify(clientUri)};`,
})

if (nuxt.options._prepare || process.env.NUXT_SESSION_PASSWORD) {
return
}
Expand Down
5 changes: 3 additions & 2 deletions server/utils/atproto/oauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import { getOAuthLock } from '#server/utils/atproto/lock'
import { useOAuthStorage } from '#server/utils/atproto/storage'
import { UNSET_NUXT_SESSION_PASSWORD } from '#shared/utils/constants'
import { OAuthMetadataSchema } from '#shared/schemas/oauth'
// @ts-expect-error virtual file from oauth module
import { clientUri } from '#oauth/config'
// TODO: limit scope as features gets added. atproto just allows login so no scary login screen till we have scopes
export const scope = 'atproto'

export function getOauthClientMetadata() {
const dev = import.meta.dev

// on dev, match in nuxt.config.ts devServer: { host: "127.0.0.1" }
const client_uri = dev ? `http://127.0.0.1:3000` : 'https://npmx.dev'
const client_uri = clientUri
const redirect_uri = `${client_uri}/api/auth/atproto`

const client_id = dev
Expand Down
Loading