Nuxt JS on Pages environment variables not working

I have correctly set all my env vars, my code seems accurate as far as i can tell yet no matter what i do pages will not use my variables
4 Replies
crossbeau
crossbeau10mo ago
Code samples and proof i have values set here - https://github.com/unjs/nitro/issues/272#issuecomment-1679889977
GitHub
Support cloudflare environment variables · Issue #272 · unjs/nitro
Reference docs: https://developers.cloudflare.com/workers/platform/environment-variables/ Related: nuxt/nuxt#14011 Normally, we allow extending runtime config using Node.js environment variables (p...
crossbeau
crossbeau10mo ago
server route sample:
server/routes/signin.js

import { createNonce } from '~/utils/auth';
import buildUrl from 'build-url';
import { defineEventHandler, setCookie } from 'h3';

export default defineEventHandler(async (event) => {
const runtimeConfig = useRuntimeConfig(event);
const nonce = createNonce();
setCookie(event, 'nonce', nonce, { secure: true });

const url = buildUrl(`https://${runtimeConfig.auth0.domain}`, {
path: 'authorize',
queryParams: {
client_id: runtimeConfig.auth0.clientID,
response_type: '',
redirect_uri: runtimeConfig.auth0.redirectUrl,
scope: '',
audience: runtimeConfig.auth0.audience,
nonce: nonce,
},
});

return sendRedirect(event, url, 302);
});
server/routes/signin.js

import { createNonce } from '~/utils/auth';
import buildUrl from 'build-url';
import { defineEventHandler, setCookie } from 'h3';

export default defineEventHandler(async (event) => {
const runtimeConfig = useRuntimeConfig(event);
const nonce = createNonce();
setCookie(event, 'nonce', nonce, { secure: true });

const url = buildUrl(`https://${runtimeConfig.auth0.domain}`, {
path: 'authorize',
queryParams: {
client_id: runtimeConfig.auth0.clientID,
response_type: '',
redirect_uri: runtimeConfig.auth0.redirectUrl,
scope: '',
audience: runtimeConfig.auth0.audience,
nonce: nonce,
},
});

return sendRedirect(event, url, 302);
});
app.vue sample

<template>
<NuxtLayout>
<NuxtLoadingIndicator />
<NuxtPage />
</NuxtLayout>
</template>

<script setup lang="ts">
const route = useRoute();
const runtimeConfig = useRuntimeConfig();
const domain = runtimeConfig.public.domain;

useHead({
titleTemplate: '%s - Leagued',
viewport: 'width=device-width, initial-scale=1',
charset: 'utf-8',
htmlAttrs: {
lang: 'en',
},
link: [
{
rel: 'apple-touch-icon',
sizes: '180x180',
href: '/favicon/apple-touch-icon.png',
},
{
rel: 'icon',
type: 'image/png',
sizes: '32x32',
href: '/favicon/favicon-32x32.png',
},
{
rel: 'manifest',
type: 'image/png',
sizes: '16x16',
href: '/favicon/favicon-16x16.png',
},
{ rel: 'manifest', href: '/favicon/site.webmanifest' },
{
rel: 'mask-icon',
color: '#5bbad5',
href: '/favicon/safari-pinned-tab.svg',
},
{ rel: 'shortcut icon', href: '/favicon/favicon.ico' },
{ name: 'msapplication-TileColor', content: '#ffc40d' },
{ name: 'msapplication-config', href: '/favicon/browserconfig.xml' },
{ name: 'theme-color', content: '#ffffff' },
{
rel: 'canonical',
href: () => `https://example.com${route.path}`,
},
],
});
</script>
app.vue sample

<template>
<NuxtLayout>
<NuxtLoadingIndicator />
<NuxtPage />
</NuxtLayout>
</template>

<script setup lang="ts">
const route = useRoute();
const runtimeConfig = useRuntimeConfig();
const domain = runtimeConfig.public.domain;

useHead({
titleTemplate: '%s - Leagued',
viewport: 'width=device-width, initial-scale=1',
charset: 'utf-8',
htmlAttrs: {
lang: 'en',
},
link: [
{
rel: 'apple-touch-icon',
sizes: '180x180',
href: '/favicon/apple-touch-icon.png',
},
{
rel: 'icon',
type: 'image/png',
sizes: '32x32',
href: '/favicon/favicon-32x32.png',
},
{
rel: 'manifest',
type: 'image/png',
sizes: '16x16',
href: '/favicon/favicon-16x16.png',
},
{ rel: 'manifest', href: '/favicon/site.webmanifest' },
{
rel: 'mask-icon',
color: '#5bbad5',
href: '/favicon/safari-pinned-tab.svg',
},
{ rel: 'shortcut icon', href: '/favicon/favicon.ico' },
{ name: 'msapplication-TileColor', content: '#ffc40d' },
{ name: 'msapplication-config', href: '/favicon/browserconfig.xml' },
{ name: 'theme-color', content: '#ffffff' },
{
rel: 'canonical',
href: () => `https://example.com${route.path}`,
},
],
});
</script>
ChronicStone
ChronicStone5mo ago
@crossbeau Did you find an answer ?
Want results from more Discord servers?
Add your server
More Posts
For some reason I can't connect the domain to the site and to the server itselfHello, for some reason when I try to connect my server minecraft and the site located on 2 differentSend emails through cloudflare worker from Mail App like Thunderbird.Is there a way I can send an email through a cloudflare worker from Thunderbird or other Mail ClientDefault DNS records for Cloudflare-hosted domain?I’ve transferred a domain to Cloudflare. It doesn’t have any DNS records because all I want to do isPricing for video deliveryWe want to use Cloudflare to deliver video files. We are going to place all our special packages simmultiple tunneling serviceswhenever i try to run the command cloudflare gives me to setup a second tunnel on my OS, it gives me[Question] Is there a better way to run multiple workers with service bindings?I am working on an app with around 10 workers all connected through service bindings with one actingReverse Proxy x ShopifyWe're transitioning to Shopify but facing limitations in checkout, payments, and currency handling.Attempting to login via OAuth... issueHi! I'm attempting to deploy a worker app developed with hono with wrangler. When I have: `wrangler trying to setup a tunnel for a cloudflare domaintheres tonnes of tutorials online on how to create a cloudflare tunnel that routes to a subdomain, bCannot deploy Nuxt app to pages. Build completes, but after publish I get a minified runtime errormy pages.dev link : woom-v2-nuxt3-cloudflare-autodeploy.pages.dev deployment id : 0ac92c74-e72e-4969