【发布时间】:2019-10-16 23:42:05
【问题描述】:
我有一个带有两个模型(客户端和用户)的 adonis.js 框架,并且使用 JWT 我想在两个模型上都进行身份验证,但它并没有真正起作用
我已尝试指定在每个模型上使用什么身份验证以及如何构建令牌、用户和客户端数据库以支持此
// I tried to set the auth.js to support them
client: {
serializer: 'lucid',
model: 'App/Models/Client',
scheme: 'jwt',
uid: 'email',
password: 'password',
options: {
secret: Env.get('APP_KEY')+'client'
}
},
//used default jwt for user model
//somewhere inside my auth function below
async clientAuth({request, auth, response}){
if(await auth.authenticator('client').attempt(email, password)){
//did some stuffs as the above worked for Client Model
let client = await Client.findBy('email', email)
// even if the auth passed, i can't store the token or generate
//the line below generate error
auth.generate(client) //says auth.generate is not a function
}
}
是否可以将 JWT 与客户端和用户模型一起使用,并且令牌功能在两者上都可以使用?我必须建立自己的身份验证令牌逻辑,这真的很忙(重新发明轮子)
【问题讨论】:
-
你的 laravel 应用中的客户端模型是否实现了可认证?
-
@Saly3301 它的 adonis.js(我实际上使用 laravel 处理多个身份验证)我只是想要一个多线程后端,这就是我选择 adonis(非常类似于 laravel)的原因
标签: node.js authentication jwt adonis.js