const express = require('express');
const passport = require('passport');
const GoogleStrategy = require('passport-google-oauth20').Strategy;
const cors = require('cors')
const app = express();
app.use(cors({
header: {
'Access-Control-Allow-Origin': '*'
},
origin: 'http://localhost:3000',
credentials: true
}));
app.get('/auth/google',
passport.authenticate('google', { scope: ['profile'] }));
app.get('/auth/google/callback',
passport.authenticate('google', { failureRedirect: '/login' }),
function(req, res) {
res.header('Access-Control-Allow-Origin: http://localhost:3000');
res.redirect('/');
});
//Routes
passport.use(new GoogleStrategy({
clientID: 'clientID',
clientSecret: 'clientSecret',
callbackURL: "http://localhost:3000/auth/google/callback"
},
function(accessToken, refreshToken, profile, cb) {
User.findOrCreate({ googleId: profile.id }, function (err, user) {
return cb(err, user);
});
}
));
//Start server
app.listen(4000, () => {
console.log('start server');
})`
app.js
const authentication = () => {
axios( {
method: 'GET',
withCredentials: true,
url: 'http://localhost:4000/auth/google/callback',
}).then((res) => console.log(res.data));
}
Перепробовал разные варианты с header, ничего не помогло