gpt4 book ai didi

error-handling - 防止错误: “NotAuthenticated: Strategy jwt is not permitted”

转载 作者:行者123 更新时间:2023-12-03 08:44:45 26 4
gpt4 key购买 nike

我使用FeathersJS作为SocketIo的API 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)

问题:
  • 为什么会出现错误?确实没有注册JWT,我将方法命名为“firebaseAuth”,但是谁在用JWT策略调用auth函数?在代码中找不到。
  • 我应该忽略还是解决它?我不愿意留下无法修复的错误,即使它没有危害。
  • 最佳答案

    找到了问题,因此,如果其他人正在到达此职位:

    在初始化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(...。问题解决了。

    关于error-handling - 防止错误: “NotAuthenticated: Strategy jwt is not permitted” ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57132026/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com