Background system login authentication step of recording space and leaves ·

1. Route to write authentication

1
router.post('/api/login', app.passport.authenticate('local', { successRedirect: '/api/login/authCallback' }));

2. // config / plugin.js install module egg-passport

exports.passport = {
enable: true,
package: ‘egg-passport’,
};

3.app.js authentication logic introduced in the introduction

module.exports = app => {
require(‘./init/session’)(app)
require(‘./init/passLocal’)(app)
};

4.init / passLocal.js logic in adding authentication

5.init / session.js Session there is a model of a function, so to create a new model in the app document folder, new Schema ({})

6. Commission found that post requests, but still behind url with parameters, carefully review the document, the original is automatically serialized to json format when axios request parameter data, in the body post's, export const fqLogin = {

async login (data) {// Note: this place to write data, axios be serialized as JSON
return the await HTTP ({
URL: '/ MyApi / API / Login',
Method: 'POST',
Data
})
}
}

7. init / passLocal.js inside. Verify req.body go in and verify code session.code consistent, if agreed, only to go down to find the user's logic

8. Find a user when calling ctx.service.users.login (user) service, then built users.js document service below, which is actually a method call to the database to find data, if found, then the login is successful. Since then, the login authentication logic is completed.

Original: Large column  back-office system login authentication steps and leaves space for recording and


Guess you like

Origin www.cnblogs.com/petewell/p/11421936.html