gpt4 book ai didi

reactjs - aws-amplify/ui-reac, 登录后可以重定向

转载 作者:行者123 更新时间:2023-12-04 13:54:33 28 4
gpt4 key购买 nike

您好,我正在尝试使用 AWS-amplify 和 react-dom 登录后重定向和更改我的路径
我需要在用户登录后将它们重定向到 localhost/main主要是因为它位于 localhost/如果有人有想法可以帮助我谢谢
我的代码:

import React from "react";
import "./App.css";
import { BrowserRouter as Router, Switch, Route } from "react-router-dom";
import Amplify from "aws-amplify";
import {
AmplifyAuthenticator,
AmplifySignUp,
} from "@aws-amplify/ui-react";
import { AuthState, onAuthUIStateChange } from "@aws-amplify/ui-components";
import awsconfig from "./aws-exports";
import Main from "./main";

Amplify.configure(awsconfig);

const AuthStateApp = () => {
const [authState, setAuthState] = React.useState();
const [user, setUser] = React.useState();

React.useEffect(() => {
return onAuthUIStateChange((nextAuthState, authData) => {
setAuthState(nextAuthState);
setUser(authData);
});
}, []);

return authState === AuthState.SignedIn && user ? (
<Router>
<Switch>
<Route path="/main">
<Main />
</Route>
</Switch>
</Router>
) : (
<AmplifyAuthenticator>
<AmplifySignUp
slot="sign-up"
formFields={[
{ type: "username" },
{ type: "password" },
{ type: "email" },
]}
/>
</AmplifyAuthenticator>
);
};

export default AuthStateApp;

最佳答案

搜索此问题后,解决方案是使用AUTH.signIn()自行设计登录和注册。和 Auth.signUp()你可以重定向之后。

关于reactjs - aws-amplify/ui-reac, 登录后可以重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64721339/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com