All Projects → eggjs → egg-userservice

eggjs / egg-userservice

Licence: other
userservice plugin for egg

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to egg-userservice

egg-session-redis
redis store for egg session
Stars: ✭ 41 (+95.24%)
Mutual labels:  egg, egg-plugin
egg-oracle
OracleDB plugin for egg
Stars: ✭ 23 (+9.52%)
Mutual labels:  egg, egg-plugin
egg-rbac
Role Based Access Control for eggjs
Stars: ✭ 32 (+52.38%)
Mutual labels:  egg, egg-plugin
egg-kafkajs
☎️kafka plugin for eggjs
Stars: ✭ 26 (+23.81%)
Mutual labels:  egg, egg-plugin
egg-elasticsearch
elasticsearch client for egg.js
Stars: ✭ 22 (+4.76%)
Mutual labels:  egg, egg-plugin
egg-exporter
Egg.js 的 Prometheus 指标收集插件,附带 Grafana 看板。
Stars: ✭ 24 (+14.29%)
Mutual labels:  egg, egg-plugin
egg-sentry
Sentry Plugin For Egg.js
Stars: ✭ 18 (-14.29%)
Mutual labels:  egg, egg-plugin
Egg Validate
validate plugin for egg
Stars: ✭ 224 (+966.67%)
Mutual labels:  egg, egg-plugin
egg-view-pug
egg view plugin for pug.
Stars: ✭ 24 (+14.29%)
Mutual labels:  egg, egg-plugin
egg-weapp-sdk
Egg的微信小程序登录会话管理SDK
Stars: ✭ 111 (+428.57%)
Mutual labels:  egg, egg-plugin
egg-vue-webpack-dev
基于egg + vue2 + webpack2 的前后端集成开发编译构建插件
Stars: ✭ 29 (+38.1%)
Mutual labels:  egg, egg-plugin
egg-view-react
egg view plugin for react
Stars: ✭ 89 (+323.81%)
Mutual labels:  egg, egg-plugin
egg-kafka-node
kafka plugin for egg.js
Stars: ✭ 36 (+71.43%)
Mutual labels:  egg, egg-plugin
egg-parameters
Merge all parameters (ctx.params, ctx.request.query, ctx.request.body) into ctx.params like Rails application.
Stars: ✭ 24 (+14.29%)
Mutual labels:  egg, egg-plugin
Egg Redis
redis plugin for egg
Stars: ✭ 234 (+1014.29%)
Mutual labels:  egg, egg-plugin
egg-grpc
grpc plugin for egg
Stars: ✭ 79 (+276.19%)
Mutual labels:  egg, egg-plugin
Egg Security
Security plugin for egg, force performance too.
Stars: ✭ 204 (+871.43%)
Mutual labels:  egg, egg-plugin
Egg Socket.io
socket.io plugin for eggjs.
Stars: ✭ 209 (+895.24%)
Mutual labels:  egg, egg-plugin
egg-aop
AOP plugin for eggjs, add DI, AOP support.
Stars: ✭ 44 (+109.52%)
Mutual labels:  egg, egg-plugin
egg-swagger
swagger-ui plugin for egg ,Demo:
Stars: ✭ 26 (+23.81%)
Mutual labels:  egg, egg-plugin

egg-userservice

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Userservice plugin for Egg.

[DEPRECATED] use https://github.com/eggjs/egg-passport instead.

This plugin provides a convention of how your application accesses current user data.

You can define the way to retrieve current user data according to the exact user strategy your application is using.

User data may be stored in:

  • cookie
  • database
  • some kind of service
  • cache system(eg. redis)
  • etc..

Whatever kind of strategy you are using, just configurate it with this plugin, and keep the way of accessing user data unchanged, for a better understanding across the entire whole egg community.


Install

$ npm i egg-userservice

Usage

  • ctx.user: current user data
  • ctx.userId: the user id of current user
  • app.config.userservice.service.getUser(ctx):
  • app.config.userservice.service.getUserId(ctx):

Configuration

Add your userservice configurations to config/config.default.js

exports.userservice = {
  service: {
    async getUser(ctx) {
      // Retrieve your user data from cookie, redis, db, whatever
      // For common web applications using cookie, you may get session id with ctx.cookies
    },

    getUserId(ctx) {
      // The way to get userId
      // eg. return ctx.user && ctx.user.userId
    }
  }
}

In your config/plugin.js

exports.userservice = {
  enable: true,
  package: 'egg-userservice',
};

For complicated applications

The way your application retrieving user data can be complicated, it may be very weird if configurating it in a config file.

A standalone plugin of your own can be a better solution. In this kind of situation, the way of accessing data with ctx.user and ctx.userId should be left unchanged.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].