[英]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
The components render UI or nothing base on authState
property.组件根据authState
属性呈现 UI 或不呈现任何authState
。 In your case authState
is signedIn
.在您的情况下authState
是signedIn
。 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.