Sve*_*ers 2 hook jwt feathersjs
我一直在寻找这个问题上如何设置FeathersJS一个JWT的子要求,但是当我打印hook.params,也没有jwt在那里。只有authenticated,query,route,provider,headers,user和payload。
因此,我仍然有一个问题:如何更改Feathers中JWT令牌的到期时间?
对于后人来说,
您可以轻松地在 config/default.json 中更改它:
{
// ...
"authentication": {
"jwtOptions": {
"expiresIn": "2 days" // Or "10h" or just a number which is interpreted as seconds
}
}
}
Run Code Online (Sandbox Code Playgroud)
找到了:)我看了一下文章中链接的代码(链接已更改,但是在浏览git repo时很容易找到),并在中看到了params,您只需要创建自己的jwt对象,这些选项就会合并创建JWT时。
因此,如果其他任何人偶然发现了这,这是我的代码:
app.service('authentication').hooks({
before: {
create: [
authentication.hooks.authenticate(config.strategies),
context => {
context.params.jwt = { expiresIn: 10 }; // 10 seconds
}
],
remove: [
authentication.hooks.authenticate('jwt')
]
}
});
Run Code Online (Sandbox Code Playgroud)