Y
Y
Yan Vetrov2019-06-21 01:23:33
Node.js
Yan Vetrov, 2019-06-21 01:23:33

Long loading after receiving data from the VK API. How to fix?

There is an app.js code in which I use passporj.js + vk-strategy for authorization, but there is a problem, after going to the authorization field and, accordingly, authorization, it does not redirect to the main page

app.use(require('cookie-parser')());
app.use(require('body-parser').urlencoded({extended: true}));
app.use(require('express-session')({secret:'keyboard cat', resave: true, saveUninitialized: true}));
app.use(passport.initialize());
app.use(passport.session());

passport.use(new VKontakteStrategy({
    clientID:     'API ID', // VK.com docs call it 'API ID', 'app_id', 'api_id', 'client_id' or 'apiId'
    clientSecret: 'SECRET_KEY',
    callbackURL:  "http://localhost:3000/auth/vkontakte/callback",
    scope: ['email'],
    profileFields: ['email', 'city', 'bdate'],
    apiVersion: '5.17'
  },
  function(accessToken, refreshToken, params, profile, done) {
      user.findOne({VKId: profile.id}, function(err, result) {
                if(!result) {
                    user.insertOne({
                        VKId: profile.id,
                        inventory: [],
                        balance: 0
                    }, function(err, result) {
                        console.log(result)
                    })
                }
        });
  }
));

passport.serializeUser(function(user, done) {
    done(null, user.id);
});

passport.deserializeUser(function(id, done) {
    user.findOne({VKId: profile.id}, function(err, result) {
        if (err) {
            done();
        }
        done(null, user)
    })
});

app.get('/auth/vkontakte/callback',
  passport.authenticate('vkontakte', { failureRedirect: '/login' }),
  function(req, res) {
    res.redirect('/');
 });

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