React Native: AWS Amplify Auth.signOut() not working



React Native noob在这里,试图在我的项目中实现AWS Amplify身份验证流。但是Auth.signOut()函数根本不起作用。当我按下logout按钮时,什么也没发生。

const onLogOutPressed = async () => {
//Auth.signOut();
try {
await Auth.signOut({ global: true });
} catch (error) {
console.log('Error Logging Out', error);
}
}

我的第一个版本纯粹是Auth.signOut(),因为这就是我下面的教程所做的。另一个指南建议使用try方法,所以我评论了第一个Auth函数,并添加了其余的

如能提供帮助,我们将不胜感激。如果需要更多信息,请告诉我,提前谢谢。

如果您使用的是Amplify的React原生UI,并使用withAuthenticator包装组件,下面的代码应该可以工作。

class App extends React.Component {
constructor(props) {
super(props);
};
...
Auth.signOut().then(() => {
this.props.onStateChange(("signedOut");
});
}

// Functional component
const App = (props) => {
...
Auth.signOut().then(() => {
this.props.onStateChange("signedOut", null);
})
}

如果您不使用React原生UI,那么您需要自己处理重定向。Auth.signOut()将只清除会话。

最新更新