Why doesn't credentials: 'include' help?

  • 0
    Hello!

    Here is the server authorization function:

    const doLogin = () => {
            setLoading(true);
            const request = fetch(baseURL+'/users/authentication/email/', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json; charset=utf-8'
                },
                body: JSON.stringify({ email, password, device: {
                    name: 'PC'} })
            });
    
            request
                .then(response => {console.log(response.headers); return response.json()})
                .then(json => {
                    setLoading(false);
                    if (json.error) {
                        setAuthError({ isError: true, errorMsg: json.error.message })
                    } else {
                        dispatch(setAuthenticated(true));
                        dispatch(setAuthData({
                            userEmail: email,
                            userPassword: password
                        }))
                        history.push('/groups');
                    }
                });
        }


    The jwt token normally arrives from the server, then we request the data:

    const searchClicked = () => {
            fetch(baseURL + '/users/' + searchEmail, {
                method: 'GET',
                credentials: 'include'
            })
                .then(response => response.json())
                .then(json => console.log(json))
        }


    and we get 401 (Unauthorized) in response.

    What's wrong?
    JavaScript Anonymous, Dec 24, 2019

  • 0 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!