Skip to content

Instantly share code, notes, and snippets.

@kvnam
Last active November 27, 2018 10:29
Show Gist options
  • Save kvnam/e7f343d8f477861a49e2d23b93659016 to your computer and use it in GitHub Desktop.
Save kvnam/e7f343d8f477861a49e2d23b93659016 to your computer and use it in GitHub Desktop.
ReactPress - Signin Action
{
"code": "jwt_auth_failed",
"data": {
"status": 403
},
"message": "Invalid Credentials."
}
{
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9qd3QuZGV2IiwiaWF0IjoxNDM4NTcxMDUwLCJuYmYiOjE0Mzg1NzEwNTAsImV4cCI6MTQzOTE3NTg1MCwiZGF0YSI6eyJ1c2VyIjp7ImlkIjoiMSJ9fX0.YNe6AyWW4B7ZwfFE5wJ0O6qQ8QFcYizimDmBy6hCH_8",
"user_display_name": "admin",
"user_email": "admin@localhost.dev",
"user_nicename": "admin",
"user_id": 1,
"token_expires": 12000
}
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