C
C
connecter2019-04-30 09:12:33
CORS
connecter, 2019-04-30 09:12:33

How to return data from the server?

Good afternoon.
There is a root

app.get('/auth/', passport.authenticate('auth', { scope: 'user_read' }));

And a callback for authorization
app.get('/auth/callback', 
  passport.authenticate('auth', {failureRedirect: 'http://localhost:3000/' }),
  function(req, res) {
    console.log(req.user.data);  // <---- мне нужно получить эти данные в компонент реакта
    res.redirect('http://localhost:3000/');
  }
);

When switching to the authorization root, an authorization request is sent via api and, if successful / unsuccessful, a callback is triggered.
So, in the component, I send a request to this page, but CORS is blocking me there
componentWillMount(){
    axios.get('http://localhost:5000/auth/').then(data => {
      this.setState({
        userInfo: data.data
      })
      console.log(this.state.userInfo)
    });
  }

5cc7e6642db05814896189.png
PS Server Settings
var cors           = require('cors');
var app = express();
app.use(cors());
app.use(function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  next();
});

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question