Skip to content

Wechat mini program auth plugin for Claypot, built on top of wxapp-auth

License

Notifications You must be signed in to change notification settings

cantonjs/claypot-wxapp-auth-plugin

Repository files navigation

claypot-wxapp-auth-plugin

Build Status

Wechat mini program auth plugin for Claypot, built on top of wxapp-auth.

Installing

$ yarn add claypot claypot-restful-plugin claypot-wxapp-auth-plugin

Usage and Example

Claypotfile.js

module.exports = {
  plugins: [
    {
      module: 'claypot-restful-plugin',
      options: {},
    },
    {
      module: 'claypot-wxapp-auth-plugin',
      options: {
        appId: '<APPID>', // required
        appSecret: '<APP SECRET>', // required
        namespace: 'wxappAuth', // `ctx.clay.wxappAuth`
        prefix: 'wxappAuth', // cache key prefix
        ttl = 172800, // cache ttl (2 days by default)
        security: 'wxapp', // `claypot-restful-plugin` security
        signKey: 'id', // sign({ [signKey]: signValue })
      },
    },
  ],
};

models/User.js

export default class Users {
	async login({ body }, ctx) {
		const { code } = body;
		const { wxappAuth } = ctx.clay;
		const { openid, sign } = await wxappAuth.login({ code });
		const { accessToken, expiresIn } = await sign({ id: openid });
		return { accessToken, expiresIn };
	}
	async getUserInfo({ body }, ctx) {
		const { wxappAuth } = ctx.clay;
		const userInfo = await wxappAuth.getUserInfo(body);
		return userInfo;
	}
	// ...
}

License

MIT

About

Wechat mini program auth plugin for Claypot, built on top of wxapp-auth

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published