Clerk Expo 错误 422 - email_code 与参数策略允许的值之一不匹配

问题描述 投票:0回答:1

我按照 clerk expo 文档,在 React Native 中创建了一个电子邮件+密码注册组件。在仪表板中启用以下选项进行注册 - Email address enabled Password and email code enabled

尽管将两个值(电子邮件和密码)传递给

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>}
javascript react-native authentication expo clerk
1个回答
0
投票

我遇到了同样的问题,我:

  1. 在仪表板中创建了一个新的 Clerk 应用程序
  2. 更新了我的 .env 文件中的
    EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY
  3. 重新运行博览会应用程序并完成注册流程

之后就成功了。不知道发生了什么!

© www.soinside.com 2019 - 2024. All rights reserved.