S
S
Senbonzakuraa2020-07-28 16:06:05
Node.js
Senbonzakuraa, 2020-07-28 16:06:05

How do components interact with each other?

I am writing a project using express and using a component approach. I have the following file structure:

components
 user
   index.js
   userModel.js
   userRouter.js
 auth
   index.js
   authRouter.js
   authController.js

As far as I understand, my components should not be connected directly, that is, it would be wrong to include a user component in the authController.js file in order to check for an existing user during authorization.

Here is the authController code:

const passport = require('passport')
const VKontakteStrategy = require('passport-vkontakte').Strategy;
const config = require('config')

passport.use(new VKontakteStrategy({
    clientID:     config.get('auth.vk.clientID'),
    clientSecret: config.get('auth.vk.clientSecret'),
    callbackURL:  `${config.get('domain')}/api/web/auth/vkontakte/callback`
  },
  function(accessToken, refreshToken, params, profile, done) {
      console.log(profile)
    // Зачем мне подключать компоненты друг к другу напрямую?
    User.findOrCreate({ vkontakteId: profile.id }, function (err, user) {
      return done(err, user);
    });
  }
));

module.exports = passport

Question - how in that case I should connect these 2 components?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Suntsev, 2020-07-28
@GreyCrew

Your question is not very clear.
Here you have an authController, in it you initialize the authorization strategy through VK, through new
VKontakteStrategy, which takes two arguments - an object with data and a callback function that will be executed after successful initialization. The components are more than connected.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question