簡體   English   中英

如何防止feathers.js返回users路由中的所有用戶

[英]How to prevent feathers.js from returning all users in the users route

我一直在使用feathers.js 一段時間了,但環顧四周后我找不到一些東西。 您如何防止經過身份驗證的用戶看到所有用戶?

當我在我的/users路線上與郵遞員進行 GET 時,如果我通過了身份驗證,我將收到在應用程序上注冊的所有用戶。 我如何防止這種情況。 我嘗試返回我自己的自定義響應,但這似乎阻止了/authentication路由。

任何幫助將不勝感激,因為羽毛非常適合使用。

您可以使用limitskip參數。 因此,當您執行 FIND (GET) 請求時,還要發送 limit: 5, skip: 0。這是在feathersjs 中進行分頁的一種方式。

你可以在這里查看: https : //docs.feathersjs.com/api/databases/common.html#pagination

目前feathers-authentication-hooks是限制查詢的最佳方式,最常用於關聯當前用戶。 因此,為了將所有請求限制為當前經過身份驗證的用戶,您可以這樣做:

const { authenticate } = require('@feathersjs/authentication');
const { setField } = require('feathers-authentication-hooks');

app.service('users').hooks({
  before: {
    all: [
      authenticate('jwt'),
      setField({
        from: 'params.user.id',
        as: 'params.query.id'
      })
    ]
  }
})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM