eggjs/egg-userservice

Name: egg-userservice

Owner: egg

Description: userservice plugin for egg

Created: 2016-07-17 06:27:53.0

Updated: 2018-05-08 14:52:01.0

Pushed: 2017-12-18 10:02:24.0

Homepage: null

Size: 18

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

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:

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
m i egg-userservice
Usage
Configuration

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

rts.userservice = {
rvice: {
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

rts.userservice = {
able: true,
ckage: '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


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.