1
0
Fork 0

Add with creds to post

This commit is contained in:
Amarpreet Minhas 2019-10-05 21:24:02 -04:00
parent b92ae0c31c
commit 40cb160740
2 changed files with 4 additions and 19 deletions

View file

@ -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 })

View file

@ -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