Firebase: 无法读取未定义的属性 (读取 ‘_getRecaptchaConfig’)

huangapple go评论72阅读模式
英文:

Firebase: Cannot read properties of undefined (reading '_getRecaptchaConfig')

问题

我需要你的帮助。

无法读取未定义的属性(读取 '_getRecaptchaConfig'

Remix 动作函数

export async function action({ request }: ActionArgs) {
	const formData = await request.formData()
	const formValues = Object.fromEntries(formData)

	invariant(
		formValues?.email && typeof formValues?.email === 'string',
		"email is empty or isn't a string type",
	)
	invariant(
		formValues?.password && typeof formValues?.password === 'string',
		"password is empty or isn't a string type",
	)

	try {
		const response = await createUserWithEmailAndPassword(
			clientAuth,
			formValues.email,
			formValues?.password,
		)
	} catch (error) {
		console.log('[] err', error)
		logger.error(getErrorMessage(error))
	}

	return null
}

表单组件

<Form
	method="post"
	className="space-y-3"
	action="/auth/signin"
	{...form.props}
	noValidate
	replace
>
	<fieldset>
		<label htmlFor="email">{t('email')}</label>
		<Input name="email" placeholder={`${t('email')}`} />
		<p aria-invalid="true">{email.error}</p>
	</fieldset>
	<fieldset>
		<label htmlFor="password">{t('password')}</label>
		<Input
			name="password"
			type="password"
			placeholder={`${t('password')}`}
		/>
		<p aria-invalid="true">{password.error}</p>
	</fieldset>
	<LoadingButton
		type="submit"
		size="lg"
		name="intent"
		value="__with_email"
		isLoading={navigation.state === 'loading'}
		className="mt-[18px] min-h-[56px] w-full text-base"
	>
		{t('createMyAccount')}
	</LoadingButton>
	<p className="mt-[18px] text-center text-base">
		{t('alreadyMember')},{''}
		<Link to="/login" className="font-bold hover:underline">
			{t('login')}
		</Link>
	</p>
</Form>

Firebase 配置

import { getAuth } from 'firebase/auth'
import { initializeApp } from 'firebase/app'

console.log(process.env.FIREBASE_API_KEY)

export const firebaseConfig = {
	apiKey: 'xxxxxxxxxxxxxxxxxxxx',
	authDomain: 'xxxxxxxx',
	projectId: 'xxxxxxxxxxx',
	storageBucket: 'xxxxx',
	messagingSenderId: 'xxxxxx',
	appId: 'xxxxxxxxxxx',
	measurementId: 'xxxxxxxx',
}

const app = initializeApp(firebaseConfig)
const auth = getAuth(app)

export { auth }
类型错误:无法读取未定义的属性(读取 '_getRecaptchaConfig'    在 createUserWithEmailAndPassword (/Users/elyseebleu/Desktop/DEV/myInspo/node_modules/@firebase/auth/src/core/strategies/email_and_password.ts:291:20)
    在 action3 (/Users/elyseebleu/Desktop/DEV/myInspo/app/routes/auth+/signin.tsx:181:26)
    在 runMicrotasks (<anonymous>)
    在 processTicksAndRejections (node:internal/process/task_queues:96:5)
    在 Object.callRouteActionRR (/Users/elyseebleu/Desktop/DEV/myInspo/node_modules/@remix-run/node/node_modules/@remix-run/server-runtime/dist/data.js:35:16)
    在 callLoaderOrAction (/Users/elyseebleu/Desktop/DEV/myInspo/node_modules/@remix-run/router/router.ts:3568:16)
    在 submit (/Users/elyseebleu/Desktop/DEV/myInspo/node_modules/@remix-run/router/router.ts:2835:16)
    在 queryImpl (/Users/elyseebleu/Desktop/DEV/myInspo/node_modules/@remix-run/router/router.ts:2770:22)
    在 Object.queryRoute (/Users/elyseebleu/Desktop/DEV/myInspo/node_modules/@remix-run/router/router.ts:2720:18)
    在 handleDataRequestRR (/Users/elyseebleu/Desktop/DEV/myInspo/node_modules/@remix-run/node/node_modules/@remix-run/server-runtime/dist/server.js:75:20)
    在 requestHandler (/Users/elyseebleu/Desktop/DEV/myInspo/node_modules/@remix-run/node/node_modules/@remix-run/server-runtime/dist/server.js:49:18)

希望这些信息对解决问题有所帮助。

英文:

I'm currently working on a Remix app with Firebase. I'm trying to implement my auth process using GoogleProvider and signInWithEmanilAndPassword. In my Remix's action when I did this implementation below to be able to signin but I get this error just below.

I need your help

Cannot read properties of undefined (reading &#39;_getRecaptchaConfig&#39;)

Remix action function

export async function action({ request }: ActionArgs) {
	const formData = await request.formData()
	// const userAgent = request.headers.get(&#39;user-agent&#39;) ?? &#39;&#39;
	// const ua = UAParser(userAgent)
	// const session = await getSession(request.headers.get(&#39;Cookie&#39;))

	const formValues = Object.fromEntries(formData)

	invariant(
		formValues?.email &amp;&amp; typeof formValues?.email === &#39;string&#39;,
		&quot;email is empty or isn&#39;t a string type&quot;,
	)
	invariant(
		formValues?.password &amp;&amp; typeof formValues?.password === &#39;string&#39;,
		&quot;password is empty or isn&#39;t a string type&quot;,
	)

	try {
		// await signOut(clientAuth)
		const response = await createUserWithEmailAndPassword(
			clientAuth,
			formValues.email,
			formValues?.password,
		)
	} catch (error) {
		console.log(&#39;[] err&#39;, error)
		logger.error(getErrorMessage(error))
	}

	return null
}

Form component

&lt;Form
				method=&quot;post&quot;
				className=&quot;space-y-3&quot;
				action=&quot;/auth/signin&quot;
				{...form.props}
				noValidate
				replace
			&gt;
				&lt;fieldset&gt;
					&lt;label htmlFor=&quot;email&quot;&gt;{t(&#39;email&#39;)}&lt;/label&gt;
					&lt;Input name=&quot;email&quot; placeholder={`${t(&#39;email&#39;)}`} /&gt;
					&lt;p aria-invalid=&quot;true&quot;&gt;{email.error}&lt;/p&gt;
				&lt;/fieldset&gt;
				&lt;fieldset&gt;
					&lt;label htmlFor=&quot;password&quot;&gt;{t(&#39;password&#39;)}&lt;/label&gt;
					&lt;Input
						name=&quot;password&quot;
						type=&quot;password&quot;
						placeholder={`${t(&#39;password&#39;)}`}
					/&gt;
					&lt;p aria-invalid=&quot;true&quot;&gt;{password.error}&lt;/p&gt;
				&lt;/fieldset&gt;
				&lt;LoadingButton
					type=&quot;submit&quot;
					size=&quot;lg&quot;
					name=&quot;intent&quot;
					value=&quot;__with_email&quot;
					isLoading={navigation.state === &#39;loading&#39;}
					className=&quot;mt-[18px] min-h-[56px] w-full text-base&quot;
				&gt;
					{t(&#39;createMyAccount&#39;)}
				&lt;/LoadingButton&gt;
				&lt;p className=&quot;mt-[18px] text-center text-base&quot;&gt;
					{t(&#39;alreadyMember&#39;)},{&#39; &#39;}
					&lt;Link to=&quot;/login&quot; className=&quot;font-bold hover:underline&quot;&gt;
						{t(&#39;login&#39;)}
					&lt;/Link&gt;
				&lt;/p&gt;
			&lt;/Form&gt;

Firebase config

import { getAuth } from &#39;firebase/auth&#39;
import { initializeApp } from &#39;firebase/app&#39;

console.log(process.env.FIREBASE_API_KEY)

export const firebaseConfig = {
	apiKey: &#39;xxxxxxxxxxxxxxxxxxxx&#39;,
	authDomain: &#39;xxxxxxxx&#39;,
	projectId: &#39;xxxxxxxxxxx&#39;,
	storageBucket: &#39;xxxxx&#39;,
	messagingSenderId: &#39;xxxxxx&#39;,
	appId: &#39;xxxxxxxxxxx&#39;,
	measurementId: &#39;xxxxxxxx&#39;,
}

const app = initializeApp(firebaseConfig)
const auth = getAuth(app)

export { auth }
TypeError: Cannot read properties of undefined (reading &#39;_getRecaptchaConfig&#39;)
    at createUserWithEmailAndPassword (/Users/elyseebleu/Desktop/DEV/myInspo/node_modules/@firebase/auth/src/core/strategies/email_and_password.ts:291:20)
    at action3 (/Users/elyseebleu/Desktop/DEV/myInspo/app/routes/auth+/signin.tsx:181:26)
    at runMicrotasks (&lt;anonymous&gt;)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at Object.callRouteActionRR (/Users/elyseebleu/Desktop/DEV/myInspo/node_modules/@remix-run/node/node_modules/@remix-run/server-runtime/dist/data.js:35:16)
    at callLoaderOrAction (/Users/elyseebleu/Desktop/DEV/myInspo/node_modules/@remix-run/router/router.ts:3568:16)
    at submit (/Users/elyseebleu/Desktop/DEV/myInspo/node_modules/@remix-run/router/router.ts:2835:16)
    at queryImpl (/Users/elyseebleu/Desktop/DEV/myInspo/node_modules/@remix-run/router/router.ts:2770:22)
    at Object.queryRoute (/Users/elyseebleu/Desktop/DEV/myInspo/node_modules/@remix-run/router/router.ts:2720:18)
    at handleDataRequestRR (/Users/elyseebleu/Desktop/DEV/myInspo/node_modules/@remix-run/node/node_modules/@remix-run/server-runtime/dist/server.js:75:20)
    at requestHandler (/Users/elyseebleu/Desktop/DEV/myInspo/node_modules/@remix-run/node/node_modules/@remix-run/server-runtime/dist/server.js:49:18)

答案1

得分: 1

我遇到了完全相同的问题,原来是我的 Firebase Auth 对象未定义。

所以,请检查你的 clientAuth 是否正确定义。

英文:

I had the exact same issue, turns out that I just had my Firebase Auth object as undefined.

So check that your clientAuth is correctly defined.

huangapple
  • 本文由 发表于 2023年6月13日 16:24:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76462999.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定