有没有办法在Feathers JS中对两个实体进行身份验证?

时间:2019-11-05 14:40:04

标签: authentication jwt feathersjs

我正在尝试向Feathers JS应用程序添加JWT身份验证,但是我真正需要的是向auth添加两个不同的实体:Executives&Clients,每个实体都重定向到Vue JS中的另一个组件。

这是我的default.json,在其中添加了这两个实体。

"strategies": [
  "jwt",
  "local",
  "client"
],
"local": {
  "name": "local",
  "entity": "user",
  "usernameField": "email",
  "passwordField": "password",
  "service": "users"
},
"client": {
  "name": "client",
  "entity": "customer",
  "usernameField": "email",
  "passwordField": "password",
  "service": "customers"
},

这是我的身份验证端点(authentication.js)

const authentication = require('@feathersjs/authentication');
const jwt = require('@feathersjs/authentication-jwt');
const local = require('@feathersjs/authentication-local');


module.exports = function (app) {
  const config = app.get('authentication');

  // Set up authentication with the secret
  app.configure(authentication(config));
  app.configure(local(config.jwt));
  app.configure(local(config.local));
  app.configure(local(config.client));
  app.configure(jwt(config.local));
  app.configure(jwt(config.client));

  // The `authentication` service is used to create a JWT.
  // The before `create` hook registers strategies that can be used
  // to create a new valid JWT (e.g. local or oauth2)
  app.service('authentication').hooks({
    before: {
      create: [
        authentication.hooks.authenticate(config.strategies)
      ],
      remove: [
        authentication.hooks.authenticate('jwt')
      ]
    }
  });
};

当我尝试通过执行人员登录时,它会正确地指向我注册用户的用户表,但是在通过客户端实体进行尝试时,它将尝试使用相同的用户表登录,因为它从该用户表中返回了一个用户对象桌子。

0 个答案:

没有答案