0

When user logs in using facebook, Im sending a error in case no email was returned from facebook (it usually doesnt happen but happened once). For some reason, I am not getting the actual error message on the frontend, but a back . Why is that? In every other case accept with facebook, it works fine sending a custom error.

frontend:

const facebookLogin = dispatch => async (response, request, lang) => {
    dispatch({type: 'SIGNIN'});
    try {
        const {code} = response.params;´
        const user = await SigninAPI.facebook(code, request.codeVerifier, lang);
       ...
        dispatch({type: 'SIGNIN_SUCCESS', payload: user})
    } catch (err) {
        dispatch({type: 'SIGNIN_ERROR', payload: err.response.data.message});
    }
    ;
};

node backend:

facebookLogin: async (req, res, next) => { const {code, codeVerifier, lang} = req.body; const {data: {access_token}} = await UserService.getFacebookAccessToken(code, codeVerifier)

    const response = await UserService.authenticateWithFacebook(access_token)
    const {email, name} = response.data;
    if (!email) throw new BaseError('No account found', 400);
  
    const userData = {...};
    const user = await User.findOne({email});
    if (user) {
        try {
            ...
            res.status(HTTP_STATUS_CODE.OK).send({...userData});
        } catch (err) {
            next(err);
        }
    } else {
        try {
            const user = await UserService.createUser({...userData});
            res.status(HTTP_STATUS_CODE.OK).send({...userData});
        } catch (err) {
            next(err)
        }
    }
},
err handler:

handleError: (err, res) => { let {status, message, name} = err;

    if (err.name === 'BaseError') {
        res.status(status).send({
            name,
            message
        });
    } else {
        res.status(500).send({
            name,
            response: err.message,
            message: "generic err"
        });
    }
}

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.