Skip to content
54 changes: 53 additions & 1 deletion config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,49 @@ export const isPreview =
process.env.CONTEXT === 'dev' ||
process.env.VERCEL_ENV === 'preview' ||
process.env.VERCEL_ENV === 'development'
export const isProduction =
process.env.CONTEXT === 'production' || process.env.VERCEL_ENV === 'production'

/**
* Environment variable `URL` provided by Netlify.
Comment thread
serhalp marked this conversation as resolved.
* This is always the current deploy URL, regardless of env.
* @see {@link https://docs.netlify.com/build/functions/environment-variables/#functions}
*
* Environment variable `VERCEL_URL` provided by Vercel.
* This is always the current deploy URL, regardless of env.
* NOTE: Not a valid URL, as the protocol is omitted.
* @see {@link https://vercel.com/docs/environment-variables/system-environment-variables#VERCEL_URL}
*
* Preview URL for the current deployment, only available in preview environments.
*/
export const getPreviewUrl = () =>
isPreview
? process.env.NUXT_ENV_URL
? process.env.NUXT_ENV_URL
: process.env.NUXT_ENV_VERCEL_URL
? `https://${process.env.NUXT_ENV_VERCEL_URL}`
: undefined
: undefined

/**
* Environment variable `URL` provided by Netlify.
* This is always the current deploy URL, regardless of env.
* @see {@link https://docs.netlify.com/build/functions/environment-variables/#functions}
*
* Environment variable `VERCEL_PROJECT_PRODUCTION_URL` provided by Vercel.
* NOTE: Not a valid URL, as the protocol is omitted.
* @see {@link https://vercel.com/docs/environment-variables/system-environment-variables#VERCEL_PROJECT_PRODUCTION_URL}
*
* Production URL for the current deployment, only available in production environments.
*/
export const getProductionUrl = () =>
isProduction
? process.env.NUXT_ENV_URL
? process.env.NUXT_ENV_URL
: process.env.NUXTENV_VERCEL_PROJECT_PRODUCTION_URL
? `https://${process.env.NUXT_ENV_VERCEL_PROJECT_PRODUCTION_URL}`
: undefined
: undefined

const git = Git()
export async function getGitInfo() {
Expand Down Expand Up @@ -92,5 +135,14 @@ export async function getEnv(isDevelopment: boolean) {
: branch === 'main'
? 'canary'
: 'release'
return { commit, shortCommit, branch, env } as const
const previewUrl = getPreviewUrl()
const productionUrl = getProductionUrl()
return {
commit,
shortCommit,
branch,
env,
previewUrl,
productionUrl,
} as const
}
13 changes: 6 additions & 7 deletions modules/oauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@ import process from 'node:process'
import { join } from 'node:path'
import { appendFileSync, existsSync, readFileSync } from 'node:fs'
import { randomUUID } from 'node:crypto'
import { getEnv } from '../config/env.ts'

export default defineNuxtModule({
meta: {
name: 'oauth',
},
setup() {
async 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
const { env, previewUrl, productionUrl } = await getEnv(nuxt.options.dev)
Comment thread
serhalp marked this conversation as resolved.
Outdated

let clientUri: string
if (env === 'preview' && previewUrl) {
clientUri = `https://${previewUrl}`
} else if (env === 'production' && prodUrl) {
clientUri = `https://${prodUrl}`
clientUri = previewUrl
} else if (env === 'release' && productionUrl) {
clientUri = productionUrl
} else {
clientUri = 'http://127.0.0.1:3000'
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
}
Expand Down
Loading