0
redux-token-auth npm 패키지를 사용하여 인증을 시도 할 때이 문제가 발생합니다. 레일 백엔드에 제안 된 패키지입니다. 나는 device_token_auth를 통합하기 위해 npm 패키지가 제공 한 단계를 따랐다. Refer here 아래는 stackTrace 및 지원 파일입니다.ReduxTokenAuthConfig가 함수가 아닙니다.
SignIn.js?9aee:29 Uncaught TypeError: (0 , _reduxTokenAuthConfig2.default) is not a function
at Login._this.onSubmit (SignIn.js?9aee:29)
at HTMLUnknownElement.callCallback (react-dom.development.js?cada:542)
at Object.invokeGuardedCallbackDev (react-dom.development.js?cada:581)
at Object.invokeGuardedCallback (react-dom.development.js?cada:438)
at Object.invokeGuardedCallbackAndCatchFirstError (react-dom.development.js?cada:452)
at executeDispatch (react-dom.development.js?cada:836)
at executeDispatchesInOrder (react-dom.development.js?cada:858)
at executeDispatchesAndRelease (react-dom.development.js?cada:956)
at executeDispatchesAndReleaseTopLevel (react-dom.development.js?cada:967)
at Array.forEach (<anonymous>
SignInComponent
import React from 'react';
import { connect } from 'react-redux';
import { signInUser } from '../actions/redux-token-auth-config';
class Login extends React.Component {
constructor(props) {
super(props);
this.state = {
email: '',
password: ''
}
}
onEmailChange = (e) => {
const email = e.target.value;
this.setState(() => ({ email }))
}
onPasswordChange = (e) => {
const password = e.target.value;
this.setState(() => ({ password }))
}
onSubmit = (e) => {
if (this.state.email && this.state.password) {
const { email, password } = this.state
signInUser({ email, password }).then((response) => {
alert(response);
}).catch((error) => {
alert(error)
})
}
}
render() {
return (
<div>
<form onSubmit={this.onSubmit}>
<input
type="text" placeholder="Email" autoFocus autoComplete="On"
value={this.state.email}
onChange={this.onEmailChange}
/>
<input type="password" placeholder="Password" autoComplete="current-password"
value={this.state.password}
onChange={this.onPasswordChange}
/>
<button>Login</button>
</form>
</div >
)
}
}
export default connect(null, { signInUser })(Login);
돌아 오는-토큰 인증-구성
import { generateAuthActions } from 'redux-token-auth'
const config = {
authUrl: "http://localhost:3000/user_auth",
userAttributes: {
firstName: 'first_name',
lastName: 'last_name',
contactNumber: 'contact_number',
ProfilePhotoUrl: 'profile_photo_url'
},
userRegistrationAttributes: {
firstName: 'first_name',
lastName: 'last_name'
}
}
const {
registerUser,
signInUser,
signOutUser,
verifyCredentials,
} = generateAuthActions(config)
export {
registerUser,
signInUser,
signOutUser,
verifyCredentials
}
StoreConfig
import { createStore, combineReducers, compose, applyMiddleware } from 'redux';
import expensesReducer from '../reducers/expenses';
import filterReducers from '../reducers/filters';
import { reduxTokenAuthReducer } from 'redux-token-auth'
import thunk from 'redux-thunk';
export default() => {
const store = createStore(
combineReducers({
reduxTokenAuth: reduxTokenAuthReducer,
expenses: expensesReducer,
filters: filterReducers
}),
compose(
applyMiddleware(thunk)
)
)
return store;
}