| 102 | |
| 103 | // register |
| 104 | export const register = (username, email, password) => async (dispatch) => { |
| 105 | try { |
| 106 | dispatch({ type: USER_REGISTER_REQUEST }) |
| 107 | |
| 108 | const config = { |
| 109 | headers: { |
| 110 | 'Content-type': 'application/json' |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | const { data } = await axios.post(`/account/register/`, |
| 115 | { 'username': username, 'email': email, 'password': password }, |
| 116 | config |
| 117 | ) |
| 118 | |
| 119 | dispatch({ |
| 120 | type: USER_REGISTER_SUCCESS, |
| 121 | payload: data |
| 122 | }) |
| 123 | |
| 124 | dispatch({ |
| 125 | type: USER_LOGIN_SUCCESS, |
| 126 | payload: data |
| 127 | }) |
| 128 | |
| 129 | localStorage.setItem('userInfo', JSON.stringify(data)) |
| 130 | } |
| 131 | catch (error) { |
| 132 | dispatch({ |
| 133 | type: USER_REGISTER_FAIL, |
| 134 | payload: error.response && error.response.data.detail ? error.response.data.detail : error.message |
| 135 | }) |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | // check token validation |
| 140 | export const checkTokenValidation = () => async (dispatch, getState) => { |