Javascript Hello.js重新登录时刷新页面
我正在使用hello.js在react应用程序上使用twitter登录Javascript Hello.js重新登录时刷新页面,javascript,twitter-oauth,hello.js,Javascript,Twitter Oauth,Hello.js,我正在使用hello.js在react应用程序上使用twitter登录 hello.init({ twitter: 'II7hpGaWFZ1n2dbpGzr59bxko', }); 我确实在上注册了应用程序 当我的页面第一次加载时,它会显示一个登录表单。用户可以点击按钮登录twitter,hello.js打开一个弹出窗口并进行身份验证。用户返回主页并显示安全内容 <button className="button button-red primary" name="login"
hello.init({
twitter: 'II7hpGaWFZ1n2dbpGzr59bxko',
});
我确实在上注册了应用程序
当我的页面第一次加载时,它会显示一个登录表单。用户可以点击按钮登录twitter,hello.js打开一个弹出窗口并进行身份验证。用户返回主页并显示安全内容
<button className="button button-red primary" name="login"
onClick={(e)=>{this.handleTwitterLogin(e)}}>
<i className="icon-twitter float-left"></i>Continue with Twitter
</button>
handleTwitterLogin = (event) => {
event.preventDefault()
event.stopPropagation()
hello.login('twitter', auth=>{
console.log('requesting twitter auth')
hello('twitter').api('me')
.then( result=>{
this.props.actions.login('twitter')
this.props.actions.updateUser({
username: result.name,
screen_name: result.screen_name,
image: result.profile_image_url_https
})
this.props.history.push('/')
})
})
}
主页现在再次显示登录表单,因为用户已注销。但是,如果用户再次单击“使用twitter登录”按钮,则页面将刷新,URL将从
/
更改为/?login=
,并且不会调用按钮的onClick处理程序handleTwitterLogin=(事件)=>
函数。再次单击该按钮将按预期启动登录过程。我不知道调用什么代码来重新加载页面,或者如何调试页面 我不确定我是否可以在JSFIDLE上使用react/redux/等获得它。我将尝试部署到glitchSteps以复制:1。2.使用twitter 3登录。单击右上角4中的配置文件图标。单击…
图标注销5。单击“使用twitter登录”按钮(应该登录,但会刷新页面),我注意到它在一个表单中,因为我没有访问JS的权限。我想这是回发。您是否在单击按钮时调用的方法中使用了e.preventDefault()
?是的,我正在调用handleTwitterLogin
函数(见上文)中的e.preventDefault()
和e.stopPropagation()
。据我所知,表单没有提交。
logout = () => {
hello.logout('twitter', ()=>{
this.props.actions.logout()
this.props.history.push('/')
})
}