Loopback.io component currentuser
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
README.md
index.js
package.json

README.md

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();
    }
  });
};