Add with creds to post
This commit is contained in:
parent
b92ae0c31c
commit
40cb160740
2 changed files with 4 additions and 19 deletions
|
@ -22,9 +22,11 @@ export const userLogin = (username, password) => async (dispatch) => {
|
|||
const response = await sudoscientist.post('/auth/signin', {
|
||||
username: username,
|
||||
password: password
|
||||
})
|
||||
},
|
||||
{withCredentials: true},
|
||||
)
|
||||
if (response.status === 401) {
|
||||
alert("Please check your credentials")
|
||||
console.log("Please check your credentials")
|
||||
}
|
||||
if (response.status === 200) {
|
||||
dispatch({ type: 'USER_LOGIN', payload: response })
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
import Cookies from 'universal-cookie';
|
||||
|
||||
const cookies = new Cookies();
|
||||
|
||||
const initialState = {
|
||||
user_logged_in: false,
|
||||
username: '',
|
||||
|
@ -12,19 +8,6 @@ const initialState = {
|
|||
export default (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case 'USER_LOGIN':
|
||||
const full_jwt = action.payload.data.jwt
|
||||
const jwt_split = full_jwt.split('.')
|
||||
const jwt_signature = jwt_split.pop()
|
||||
const jwt_header_payload = jwt_split.join('.')
|
||||
cookies.set("jwt.signature", jwt_signature,
|
||||
{
|
||||
path: '/',
|
||||
httpOnly: true
|
||||
})
|
||||
cookies.set("jwt.header_payload", jwt_header_payload,
|
||||
{
|
||||
path: '/',
|
||||
})
|
||||
return {...state, ...{
|
||||
username: action.payload.data.username,
|
||||
user_logged_in: true
|
||||
|
|
Reference in a new issue