最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

authentication - Accesing express server for auth2 return cors error - Stack Overflow

matteradmin4PV0评论

Im on production trying to use google auth 2.0 with passport on my express js backend.

origin: function(origin, callback) {
 if (!origin || allowedOrigins.includes(origin)) {
   callback(null, origin); // Return the specific origin, not a wildcard
 } else {
   callback(new Error('Not allowed by CORS policy'));
 }
},
credentials: true,
methods: ['GET', 'POST', 'OPTIONS'],
allowedHeaders: ['Content-Type', 'Authorization', 'Accept'],
exposedHeaders: ['Set-Cookie']
}));

on my protected route (frontend) I fetch check-auth

          credentials: 'include', 
          method: 'GET',
          headers: {
            'Content-Type': 'application/json',
          },
        });   ````

and I get a cors error ```Access to fetch at '' from origin '' has been blocked by CORS policy: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'.```

pulled my hair for 12 hours now ! nothing worked 

login logic: I git api/v1/auth - > backend redirects to google -> callback url is dashboard that is a protected route and on protected route we check-auth 

Thank you for your help :) 

Post a comment

comment list (0)

  1. No comments so far