Prevent error: "NotAuthenticated: Strategy jwt is not permitted"

Prevent error: "NotAuthenticated: Strategy jwt is not permitted"

我有 FeathersJS 作为 API 带有 SocketIo 的 Rest 服务器。对于身份验证,我使用 Firebase 并从客户端发送 fbToken,在服务器上检查它并进行相应的身份验证。这是建立在 JWT 模型之上的。 一切正常,除非我重新启动服务器。虽然我确实捕获了 socket.on("reconnect_attempt", ()=>{... authentication function...} 并且它有效,但在重新验证之前我仍然遇到错误:

error: NotAuthenticated: Strategy jwt is not permitted
    at new NotAuthenticated (...my-path...\back-end\node_modules\@feathersjs\errors\lib\index.js:93:17)
    at Object.<anonymous> (...my-path...\back-end\node_modules\@feathersjs\authentication\lib\hooks\authenticate.js:31:29)
    at Object.<anonymous> (...my-path...\kludi\back-end\node_modules\feathers-hooks-common\lib\common\iff-else.js:17:63)
    at ...my-path...\back-end\node_modules\feathers-hooks-common\node_modules\@feathersjs\commons\lib\hooks.js:164:73
    at processTicksAndRejections (internal/process/task_queues.js:89:5)

问题:

  1. 为什么会出现错误?确实JWT没有注册,我把方法命名为"firebaseAuth"但是谁在用JWT策略调用auth函数呢?在代码中找不到。

  2. 我应该忽略它还是解决它?我不喜欢不修复错误,即使它没有害处。

发现问题所以如果其他人看到这个帖子:

确保你的新配置初始化socketIo之前,否则它会尝试使用JWT。 在我的例子中是:

restApi.configure(auth(
        {
            header    : 'Authorization', // the default authorization header for REST
            prefix    : '', // if set will add a prefix to the header value. for example if prefix was 'JWT' then the header would be 'Authorization: JWT eyJ0eXAiOiJKV1QiLCJhbGciOi...'
            path      : '/..........', // the server-side authentication service path
            strategy  : 'firebase_strategy', // the name of the JWT authentication strategy
            entity    : 'users', // the entity you are authenticating (ie. a users)
            service   : 'users', // the service to look up the entity
            cookie    : 'token', // the name of the cookie to parse the JWT from when cookies are enabled server side
            storageKey: 'token', // the key to store the accessToken in localstorage or AsyncStorage on React Native
            storage   : localStorage // Passing a WebStorage-compatible object to enable automatic storage on the client.
        }
    ));

const socket = io(...紧随其后。问题已解决。