Passport js fails to maintain session in cross-domain

前端 未结 3 1634
半阙折子戏
半阙折子戏 2020-12-08 08:39

I am using passport JS, express and mongoose to make an API. When I test it in same domain it maintain session and works fine. But in cross domain it fails. Any clue how can

3条回答
  •  既然无缘
    2020-12-08 09:16

    Allow the credentials to be shared by setting Access-Control-Allow-Credentials header. (I am not sure why you have commented in your code)

    res.header("Access-Control-Allow-Credentials", "true");
    

    then pass the credentials from javascript through XHR object.

    xhr.withCredentials = true;
    

提交回复
热议问题