Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application is not able access environment variables. #4508

Closed
IzaanAnwar opened this issue Jun 20, 2024 · 1 comment
Closed

Application is not able access environment variables. #4508

IzaanAnwar opened this issue Jun 20, 2024 · 1 comment

Comments

@IzaanAnwar
Copy link

I am using nextjs with trpc and @t3-oss/env-core
This is my sst.cinfig.ts

export default $config({
  app(input) {
    return {
   ...........
    };
  },
  async run() {
    const emailQueue = new sst.aws.Queue("EmailQueue");
    emailQueue.subscribe("src/utils/lambdas/invite.handler");
    const emailLambda = new sst.aws.Function("SendInviteEmail", {
      handler: "src/utils/lambdas/invite.handler",
      link: [emailQueue],
      timeout: "90 seconds",
      environment: {
        DATABASE_URL: process.env.DATABASE_URL,
      },
    });
    new sst.aws.Nextjs("Galzzy", {
      link: [emailQueue],
      environment: {
        AUTH_SECRET: process.env.AUTH_SECRET,
        GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID,
        GOOGLE_CLIENT_SECRET: process.env.GOOGLE_CLIENT_SECRET,
        DATABASE_URL: process.env.DATABASE_URL,
        NEXT_PUBLIC_WEBSITE_URL: process.env.NEXT_PUBLIC_WEBSITE_URL,
         // so on .....
      },
    });
  },
});

and this is the setup for type safe envs

import { createEnv } from "@t3-oss/env-core";
import { z } from "zod";

export const env = createEnv({
  server: {
    DATABASE_URL: z.string().url(),
    GOOGLE_CLIENT_ID: z.string(),
    GOOGLE_CLIENT_SECRET: z.string(),
    AUTH_SECRET: z.string(),
    NEXT_PUBLIC_WEBSITE_URL: z.string(),
    // so on......

  },
  runtimeEnv: process.env,
  emptyStringAsUndefined: true,
});

When I am trigrring lamnda in dev I am getting

 +2562047h   ❌ Invalid environment variables: {
|  +2562047h     DATABASE_URL: [ 'Required' ],
|  +2562047h     GOOGLE_CLIENT_ID: [ 'Required' ],
|  +2562047h     GOOGLE_CLIENT_SECRET: [ 'Required' ],
|  +2562047h     AUTH_SECRET: [ 'Required' ],
|  +2562047h     STRIPE_SECRET_KEY: [ 'Required' ],
|  +2562047h     NEXT_PUBLIC_WEBSITE_URL: [ 'Required' ],
//// .................... etc..
|  +2562047h   }

When deployed I can not even access some pages as it throws Status 500 error and in logs it shows the same env missing.
I am stuck at it for 3 days now... :{

@IzaanAnwar
Copy link
Author

It seem I need to hard code The value in sst.config like

{
   environment: {
       SOME:"value" // hard coded value
   }
}

@thdxr thdxr transferred this issue from sst/ion Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant