Last active
November 27, 2018 10:29
-
-
Save kvnam/e7f343d8f477861a49e2d23b93659016 to your computer and use it in GitHub Desktop.
ReactPress - Signin Action
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"code": "jwt_auth_failed", | |
"data": { | |
"status": 403 | |
}, | |
"message": "Invalid Credentials." | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9qd3QuZGV2IiwiaWF0IjoxNDM4NTcxMDUwLCJuYmYiOjE0Mzg1NzEwNTAsImV4cCI6MTQzOTE3NTg1MCwiZGF0YSI6eyJ1c2VyIjp7ImlkIjoiMSJ9fX0.YNe6AyWW4B7ZwfFE5wJ0O6qQ8QFcYizimDmBy6hCH_8", | |
"user_display_name": "admin", | |
"user_email": "admin@localhost.dev", | |
"user_nicename": "admin", | |
"user_id": 1, | |
"token_expires": 12000 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const userSignin = (user) => { | |
return dispatch => { | |
axios.post("/simple-jwt-authentication/v1/token", user) | |
.then(response => { | |
let userDets = { | |
username: response.data.user_nicename, | |
email: response.data.user_email, | |
displayname: response.data.user_display_name | |
}; | |
//Set token and email in local storage in case Redux data is lost such as on reload | |
localStorage.setItem("token", response.data.token); | |
localStorage.setItem("email", response.data.user_email); | |
dispatch({type: "USER_SIGNIN_SUCCESS", userDets: userDets, token: response.data.token}); | |
}).catch(err => { | |
dispatch({type: "USER_SIGNIN_FAIL", error: err}); | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment