簡體   English   中英

放大反應原生自定義登錄

[英]Amplify react native custom SignIn

我正在使用來自 AWS amplify 的 AWS aws-amplify-react-native withAuthenticator組件。 我可以為 signUp <SignUp signUpConfig={signUpConfig} />執行此操作,我也想自定義登錄、ConfirmSignUp、ForgotPassword 屏幕,而無需從頭開始編寫自己的組件。

signUp 配置似乎是可行的,因為signUpConfig是此類的一部分https://github.com/aws-amplify/amplify-js/blob/master/packages/aws-amplify-react-native/src/Auth/SignUp.tsx #L47

但同樣不適用於 singIn 和其他組件。 是否有自定義登錄、ConfirmSignUp、ForgotPassword 屏幕的替代方案。

注意[1] - 我無法使用aws-amplify-react-native Authenticator組件,SignUp 屏幕顯示在頁面的一半上,顯然它有渲染錯誤。

注意[2] - 我也無法使用來自@aws-amplify/ui-react Authenticator ,似乎它僅用於 react 而不是 react-native。 雖然 doc 說它也適用於 react-native。

您必須使用來自 aws-amplify 的Auth 我做了這樣的事情。

/* Import the Amplify Auth API */
import { Auth } from 'aws-amplify';

export default function LoginScreen() {

   const login = async () => {
      if (validateInputFields(formData)) {
         try {
           await Auth.signIn(formData.email, formData.password);
           goToHomeScreen();
         } catch (err) { console.log({ err }); }
      }
   }

   return (
      <View>
         
         {/* Email and Password fields /*}

         <Button title="Login" onPress={() => login()} />
      </View>
   )
}

該文檔也有用於注冊的 API 👍

https://docs.amplify.aws/guides/authentication/custom-auth-flow/q/platform/js/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM