我正在尝试使用'react-google-login'进行社交登录。
根目录下的.env文件
NEXT_PUBLIC_GOOGLE_CLIENT_ID=askfjaskf
Ready.tsx
import { GoogleLogin } from "react-google-login";
<GoogleLogin
clientId={process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID}
render={(props) => (
<div onClick={props.onClick}>
<div>구글 로그인</div>
</div>
)}
onSuccess={(res) => {
const { profileObj } = res as any;
setStep(AuthStep.AGREE);
}}
onFailure={(res) => {
console.log("Google Error", res);
}}
/>
在clientId中,它说
没有重载与此调用匹配。 第1个重载('(props: GoogleLoginProps | Readonly): GoogleLogin')产生了以下错误。 类型“string | undefined”不能赋值给类型“string”。 类型“undefined”不能赋值给类型“string”。 第2个重载('(props: GoogleLoginProps, context: any): GoogleLogin')产生了以下错误。 类型“string | undefined”不能赋值给类型“string”。 类型“undefined”不能赋值给类型“string”。ts(2769) index.d.ts(80, 12):所期望的类型来自于在此处声明的“clientId”属性,其类型为“IntrinsicAttributes & IntrinsicClassAttributes & Readonly & Readonly<...>”。
我不知道为什么它可以是undefined。 在本地可行但在生产环境部署时却不行。有人能帮忙吗?
next-env.d.ts
中添加对新文件的引用。我将文件命名为environmnt.d.td
,vs code会自动识别它。 - chuckieDubnext-env.d.ts
文件。相反,应创建一个单独的filename.d.ts
文件,然后将其添加到您的tsconfig.json
文件中的include
属性下 - Nextjs doc link。 - shaahiin