I am having some issues with deploying a nextjs ap...
# seed
t
I am having some issues with deploying a nextjs app where the env variables are not being picked up - even though they are set in seed - and also defined in stack too. Here is how I am defining it in my stack file. Locally or when deploying dev - it uses the env.local file. But I defined the below so it can use the env variables too. Is this the correct way to make sure the variables are passed to nextjs api functions?
Copy code
const site = new sst.NextjsSite(this, "Site", {
      path: "frontend",
      environment: {
        REGION: scope.region,
        TABLE_NAME: table.tableName,
        AUTH0_SECRET: process.env.AUTH0_SECRET,
        AUTH0_BASE_URL: process.env.AUTH0_BASE_URL,
        AUTH0_ISSUER_BASE_URL: process.env.AUTH0_ISSUER_BASE_URL,
        AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID,
        AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET,
      },
    });
f
Hey @Tharshan, can you send me a link to the build in SEED?
I can take a look at if the env vars are set correctly.
t
Sure! Will dm you the link. I did find a workaround by doing this.
Copy code
before_build:
  - cd src && npm install
  - echo $SEED_STAGE_NAME
  - echo $PWD
  - cp src/.env.$SEED_STAGE_NAME src/.env
But it did mean I had to commit these files
f
Just to clarify, you also set these environments on SEED like this https://seed.run/docs/storing-secrets.html?
t
Yep - that’s correct
f
So in the build you shared, it seems these environment variables are picked up correctly.
t
Right - ok. So when the nextjs build is happening - it’s not used or getting picked up
Should it just work without any changes to the stack?
These env are needed to be accessed by the nextjs API functions
f
Yeah it should.. hmm.. can you try console logging them, ie.
Copy code
console.log(process.env.AUTH0_SECRET);
console.log(process.env.AUTH0_BASE_URL);
...
const site = new sst.NextjsSite(this, "Site",
...
Also, which version of SST are you using?
t
0.48
Kicking off a build now
f
Can you also try to update to the latest SST v0.50.2? There was a bug fix in v0.49.2 that might be related to this.
t
Sure - will do
Is there an upgrade command?
or shall I just update package json directly
f
Copy code
$ npx sst update 0.50.2
$ yarn sst update 0.50.2
depending on ur package manager
t
btw is there a way to set that AUTH0_BASE_URL dynamically based on the deployed URL
So where abouts should I see that console log?
Oh actually
Just above
Copy code
Building Next.js site src
I see the output
Let me remove my before_build stuff and try it
The build succeeds but the auth0 callback fails
f
hmm.. you mean the auth0 callback works with the workaround, and fails without it?
t
That’s right
Will send you the link