Wechat miniprogram passport plugin for egg.
Open https://uniheart.herokuapp.com/ to see the result.
$ npm i egg-passport-weapp --save
// {app_root}/config/plugin.[t|j]s
exports.passportWeapp = {
enable: true,
package: "egg-passport-weapp"
};
// {app_root}/config/config.default.[t|j]s
exports.passportWeapp = {
key: "your oauth key",
secret: "your oauth secret"
};
// {app_root}/app/router.js
app.passport.mount("weapp", app.config.passportWeapp);
router.get("/passport/weapp/callback", ctx => {
// Now get you get ctx.user, write your login logic here,
// for example, write session
ctx.session.userId = ctx.user.id;
// And then return something instead of redirect
ctx.body = ctx.user;
});
see config/config.default.ts for more detail.
Wechat Mini Program | Wechat Mini Program Demo version |
---|---|
Please open an issue here.
npm run test-local