我按照 clerk expo 文档,在 React Native 中创建了一个电子邮件+密码注册组件。在仪表板中启用以下选项进行注册 -
尽管将两个值(电子邮件和密码)传递给
prepareEmailAddressVerification
函数,但我仍然收到错误 -
{
"status": 422,
"clerkError": true,
"errors": [
{
"code": "form_param_value_invalid",
"message": "is invalid",
"longMessage": "email_code does not match one of the allowed values for parameter strategy",
"meta": {
"paramName": "strategy"
}
}
]
}
我不明白为什么会出现这个错误。
代码-
auth 功能在这里 -
const onSignUpPress = async () => {
if (!isLoaded) {
return;
}
try {
await signUp.create({
emailAddress,
password,
});
await signUp.prepareEmailAddressVerification({ strategy: "email_code" });
setPendingVerification(true);
} catch (err) {
setErrorList(err?.errors);
console.error(JSON.stringify(err, null, 2));
}
};
const onPressVerify = async () => {
if (!isLoaded) {
return;
}
try {
const completeSignUp = await signUp.attemptEmailAddressVerification({
code,
});
if (completeSignUp.status === 'complete') {
await setActive({ session: completeSignUp.createdSessionId });
router.replace('/');
} else {
console.error(JSON.stringify(completeSignUp, null, 2));
}
} catch (err) {
console.error(JSON.stringify(err, null, 2));
}
};
注册视图的代码是 -
{!showLogin &&
<View style={styles.subContainer}>
{!pendingVerification && (
<>
<TextInput
style={styles.input}
autoCapitalize="none"
value={emailAddress}
placeholder="Email..."
onChangeText={(email) => setEmailAddress(email)}
/>
{errorList.map((error, index) =>
error.meta.paramName === 'email_address' && (
<Text key={index} style={styles.errorText}>{error.message}</Text>
)
)}
<TextInput
style={styles.input}
value={password}
placeholder="Password..."
secureTextEntry={true}
onChangeText={(password) => setPassword(password)}
/>
{errorList.map((error, index) =>
error.meta.paramName === 'password' && (
<Text key={index} style={styles.errorText}>{error.message}</Text>
)
)}
<Button style={styles.button} title="Sign Up" onPress={onSignUpPress} />
</>
)}
{pendingVerification && (
<>
<TextInput
value={code}
placeholder="Code..."
onChangeText={(code) => setCode(code)}
/>
<Button title="Verify Email" onPress={onPressVerify} />
</>
)}
<View>
<Text>Already have an account?</Text>
<TouchableOpacity style={styles.pillButton} onPress={()=>setShowLogin(true)}>
<Text style={styles.pillButtonText}>Log In</Text>
</TouchableOpacity>
</View>
</View>}
我遇到了同样的问题,我:
EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY
之后就成功了。不知道发生了什么!