Skip to content

guanbo/loopback-component-currentuser

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 

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

About

Loopback.io component currentuser

Resources

Stars

Watchers

Forks

Packages

No packages published