-
Notifications
You must be signed in to change notification settings - Fork 54
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
Smooth integration with next.js , env.local and alternative to getContentfulEnvironment #104
Comments
Altough, even |
For those who on windows. Install
|
If you don't want to install any additional dependencies you can use nextjs env library directly const { loadEnvConfig } = require("@next/env");
const contentful = require("contentful-management");
module.exports = async function() {
loadEnvConfig(process.env.PWD);
const client = contentful.createClient({
accessToken: process.env.CONTENTFUL_MANAGEMENT_TOKEN,
})
return client
.getSpace(process.env.CONTENTFUL_SPACE_ID)
.then(space => space.getEnvironment(process.env.CONTENTFUL_ENVIRONMENT))
} |
Hello, I am having an issue with the Image component from Next and typescript. I have types like this
But I need to do "as string" when I want to use image the asset like so, I would like to not have to do this on every single image, right?
The error message I get if I don't is: Type 'string | AssetFile | undefined' is not assignable to type 'string | StaticImport'. but I cannot modify the generated file to change the type, how should I go about this? I'm asking here because it is related to NextJS, I hope that is fine, I can create a stack overflow question or another issue with no problems. Thanks |
That's not a NextJS issue, your types looks fine. If you cannot change this then you need to check if it's set before loading your image const icon = item.icon?.fields.file?.url;
if (!icon) {
return null;
}
return <Image
src={icon}
alt={item.icon?.fields.description || 'no description'}
width="200"
height="85"
/> |
Hello!
First of all, would like to say that your app is a game changer for contentful.
I'm using Next.js (Commerce variant) and would like to have a smooth way to adopt your package.
First, of all, for the sake of security we aim to store environment variables in
env.local
file which is out of git control. It's a common approach and also is adoped in next.js ecosystem.So, it's not automatically works with
env.local
, which should be fixed on the library level.And the second, I would like to have an alternative to a commonjs syntax of
getContentfulEnvironment
and the file itself. The problem is I have to duplicate client setup logic in typescript and then in javascript only for your library.Thanks!
The text was updated successfully, but these errors were encountered: