I’m using Cognito in my Next JS (v14.0.3) app. To integrate, I utilized aws-amplify
library. Following is my aws configuration file
...
const awsConfig: ResourcesConfig = {
Auth: {
Cognito: {
userPoolId: NEXT_PUBLIC_USER_POOL_ID,
userPoolClientId: NEXT_PUBLIC_CLIENT_ID,
loginWith: {
oauth: {
domain: NEXT_PUBLIC_COGNITO_DOMAIN,
scopes: ['openid', 'email', 'profile'],
redirectSignIn: [BASE_URL],
redirectSignOut: [BASE_URL],
responseType: 'code',
},
},
},
},
};
export default awsConfig;
I need my BASE_URL
to be http://localhost:3000
when I’m in dev mode, while https://my-prod-site.com
when in prod mode. How should I do it?
I tried this
const BASE_URL =
process.env.NODE_ENV === 'development'
? 'http://localhost:' + process.env.PORT
: process.env.HOST_URL;
It works on the server side, BASE_URL
is getting set to http://localhost:3000
. But this export file is used in the client side, so I’m guessing process.env.PORT
is rendered undefined
, since PORT
is not prefixed by NEXT_PUBLIC_
. Is updating my environment variables with a NEXT_PUBLIC_
prefixed value my only way?
hn719 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.