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

Error: [Secret variable] is not linked #4381

Closed
f1lander opened this issue Jul 24, 2024 · 4 comments
Closed

Error: [Secret variable] is not linked #4381

f1lander opened this issue Jul 24, 2024 · 4 comments
Assignees

Comments

@f1lander
Copy link

I have a problem with sst secrets, I deployed the app to prod, no errors but when this loads, it says the error about the secret is not linked.

image

my sst config file

/// <reference path="./.sst/platform/config.d.ts" />

export default $config({
 app(input) {
   return {
     name: 'drosera',
     removal: input?.stage === 'production' ? 'retain' : 'remove',
     home: 'aws',
     providers: { aws: true },
   };
 },
 async run() {
   const WalletConnectionProjectId = new sst.Secret('WalletConnectionProjectId');
   const AlchemyApiKey = new sst.Secret('AlchemyApiKey');
   const bucket = new sst.aws.Bucket("DroseraBucket", {
     public: true,
   });
   new sst.aws.Nextjs('Drosera', {
     link: [WalletConnectionProjectId, AlchemyApiKey, bucket],
   });
 },
});
@jayair
Copy link
Contributor

jayair commented Jul 26, 2024

And you set the secret for the prod as well sst secret set --stage prod?

@jayair jayair self-assigned this Jul 26, 2024
Copy link
Contributor

thdxr commented Aug 1, 2024

this is a nextjs thing - you cannot use serverside code on the frontend
if you would like to pass information to the frontend you need to do it through an environment variable prefixed NEXT_PUBLIC_

@thdxr thdxr closed this as completed Aug 1, 2024
@thdxr thdxr assigned thdxr and unassigned jayair Aug 1, 2024
@f1lander
Copy link
Author

f1lander commented Aug 8, 2024

And you set the secret for the prod as well sst secret set --stage prod?

Yes sir

@f1lander
Copy link
Author

f1lander commented Aug 8, 2024

this is a nextjs thing - you cannot use serverside code on the frontendif you would like to pass information to the frontend you need to do it through an environment variable prefixed NEXT_PUBLIC_

So sorry I was OOO, I ended doing this

async run() {
    const WalletConnectionProjectId = new sst.Secret(
      'WalletConnectionProjectId',
    );
    const AlchemyApiKey = new sst.Secret('AlchemyApiKey');
    const bucket = new sst.aws.Bucket('DroseraBucket', {
      public: true,
    });
    new sst.aws.Nextjs('Drosera', {
      link: [WalletConnectionProjectId, bucket],
      domain: {
        name: 'app.devnet.drosera.io',
        dns: sst.cloudflare.dns(),
      },
      environment: {
        NEXT_PUBLIC_WALLET_CONNECTION_PROJECT_ID:
          WalletConnectionProjectId.value,
        NEXT_PUBLIC_ALCHEMY_API_KEY: AlchemyApiKey.value,
      },
    });
  },

setting the secrets values using the sst secret add and access to them in the run method and then set the values in the environment prop in the nextjs app instance, I was trying access in the code itself as thedocs says.

import { Resource } from "sst";

console.log(Resource.MySecret.value);

and I could access but when the problem was when I deploy tell me the resources is not linked as you see the error.

@thdxr

@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

3 participants