简体   繁体   English

AWS Amplify - React Authenticator 组件不可见

[英]AWS Amplify - React Authenticator Components not visible

Building an Authentication UI with https://aws-amplify.github.io/media/ui_library使用https://aws-amplify.github.io/media/ui_library构建身份验证 UI

import { Authenticator } from 'aws-amplify-react'
import Amplify from 'aws-amplify';

Amplify.configure(aws_exports);

const AppWithAuth = () => (
 <Authenticator />
)

https://aws-amplify.github.io/docs/js/authentication#using-the-authenticator-component-directly https://aws-amplify.github.io/docs/js/authentication#using-the-authenticator-component-directly

Using React Developer Tools to inspect, Components are visible in React View使用 React Developer Tools 检查,组件在 React View 中可见

在此处输入图片说明

But not in DOM view of Browser但不在浏览器的 DOM 视图中在此处输入图片说明

so, the various components of Authenticator like Greetings and SignIn are not showing up in DOM.因此,身份验证器的各种组件(如 Greetings 和 SignIn)并未出现在 DOM 中。 How do you make them visible in Browser你如何使它们在浏览器中可见

[Auth and AuthData state after logging in] 4 【登录后的Auth和AuthData状态】 4

[Console.logs] 5 [控制台.logs] 5

The components render UI or nothing base on authState property.组件根据authState属性呈现 UI 或不呈现任何authState In your case authState is signedIn .在您的情况下authStatesignedIn So only Greetings would render some UI.所以只有Greetings会渲染一些 UI。

the various components of Authenticator like Greetings and SignIn are not showing up in DOM. Authenticator 的各种组件(如 Greetings 和 SignIn)未显示在 DOM 中。

Seeing that your authState is currently at signedIn , you are literally already signed in. That's why the <SignIn> component is not visible/rendered.看到您的authState当前位于signedIn ,您实际上已经登录。这就是<SignIn>组件不可见/呈现的原因。 If you want to see the <SignIn> component working, your authState should be in "signIn" value, and you can try to hard-code it as an initial state for seeing it in action.如果您想看到<SignIn>组件工作,您的authState应该在"signIn"值中,您可以尝试将其硬编码为初始状态以查看它的运行情况。

import React from "react";
import { Authenticator } from "aws-amplify-react";
import Amplify from "aws-amplify";
import aws_exports from "./aws-exports";

Amplify.configure(aws_exports);

const AppWithAuth = () => (
  <Authenticator
    // Optionally hard-code an initial state
    authState="signIn"
  />
);

As for the <Greetings> it should show up if your state is signedIn .至于<Greetings>如果您的状态是signedIn它应该显示。 You can alternatively try using the withAuthenticator Higher Order Component.您也可以尝试使用withAuthenticator高阶组件。

import React from "react";
import { withAuthenticator } from "aws-amplify-react";
import Amplify from "aws-amplify";
import aws_exports from "./aws-exports";

Amplify.configure(aws_exports);

const App = () => {
  return (
    <div>
      <h1>Hello world!</h1>
      <p>This is your own App Component</p>
    </div>
  );
};

export default withAuthenticator(App, {
  // Render a sign out button once logged in
  includeGreetings: true
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 aws-放大-反应。 身份验证器组件-退出按钮 - aws-amplify-react . Authenticator Component - Signout Button 使用 React 和 Ant Design Pro / UmiJS 实施 AWS Amplify Authenticator - Implement AWS Amplify Authenticator using React and Ant Design Pro / UmiJS 用于打字稿问题的 AWS Amplify @aws-amplify/ui-react Authenticator 功能道具类型 - AWS Amplify @aws-amplify/ui-react Authenticator function prop types for typescript issues AWS Amplify Authenticator UI 确认登录错误 - AWS Amplify Authenticator UI confirm signin error AWS Amplify HOC Authenticator React 不会将 authState 属性传递给包装的组件 - AWS Amplify HOC Authenticator React does not pass authState property to wrapped component 如何在应用程序的任何位置使用 AWS Amplify react 组件 - How to Use AWS Amplify react components anywhere in an application 我已经在 AWS amplify 上部署了新的 React 代码,但网站上仍然看不到更改?? 如何解决这个问题? - I have deployed the new React code on AWS amplify but the changes are still not visible on the website?? How to solve this issue? 我们可以仅将 AWS amplify 用于其反应库(组件)而不是后端 cli 吗? - Can we use AWS amplify only for its react library (components) but not the backend cli? 放大 UI 身份验证器组件 - Amplify UI Authenticator Component 扩展打字稿中的AWS Amplify Auth组件 - Extending AWS Amplify Auth components in typescript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM