我正在查看使用react,redux和auth0作为登录场景的auth0示例项目here。不过我有点困惑,我们称之为this.props.doAuthentication()
对使用react和redux的auth0锁示例感到困惑
// App.js
import { loginUser, fetchQuote, doAuthentication, fetchSecretQuote } from '../actions'
// add a constructor
constructor(props) {
super(props)
this.props.doAuthentication()
}
这个特殊的例子下面是动作定义
// actions.js
...
const lock = new Auth0Lock('YOUR_CLIENT_ID', 'YOUR_CLIENT_DOMAIN');
export function login() {
// display lock widget
return dispatch => {
lock.show();
}
}
// Listen to authenticated event and get the profile of the user
export function doAuthentication() {
return dispatch => {
lock.on("authenticated", function(authResult) {
lock.getProfile(authResult.idToken, function(error, profile) {
if (error) {
// handle error
return dispatch(lockError(error))
}
localStorage.setItem('profile', JSON.stringify(profile))
localStorage.setItem('id_token', authResult.idToken)
return dispatch(lockSuccess(profile))
});
});
}
}
...
我是新来的终极版,所以也许这是一个明显的答案,但
doAuthentication绑定到App.js中的道具在哪里?假设App.js是顶级的根应用程序组件。
不做认证生成一个需要调度参数的函数吗?为什么我们不使用doAuthentication()的返回函数在构造函数中做任何事情?如果我们不将返回的函数赋值给任何东西,
this.props.doAuthentication
是否会持续存在或有任何影响?它不应该像doAuthentication()(someDispatchFunction)
这样的调度功能从哪里来?