1.0.1 • Published 7 years ago

loopback-component-currentuser v1.0.1

Weekly downloads
4
License
ISC
Repository
github
Last release
7 years ago

Loopback current user component


Base on loopback3 current context package current user for loopback operation hooks

Install

> npm install loopback-component-currentuser

Config

./server/component-config.json

{
  ...
    "loopback-component-currentuser": {
      "filter" : {
        "include": ["userIdentities", "userCredentials"]
     },
     "user": "user"
  }
  ...
}

Usage

'use strict';

module.exports = (Deal) => {
  Deal.observe('before save', (ctx, next)=>{
    if (ctx.instance) {
      if (ctx.isNewInstance) {
        if (ctx.options.accessToken) {
          console.log(ctx.options.currentUser);
        }
      }
      next();
    } else {
      next();
    }
  });
};