Giter VIP home page Giter VIP logo

egg-userservice's Introduction

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

egg-userservice's People

Contributors

atian25 avatar bugss avatar dead-horse avatar fengmk2 avatar julyyq avatar popomore avatar shaoshuai0102 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.