简体   繁体   English

在jwt-auth中是否可以对两个模型使用一个令牌?

[英]Is that possible in jwt-auth to use one token for two Models?

I use jwt-auth for authentication and i have two authenticatable models in my project "User" and "Company". 我使用jwt-auth进行身份验证,并且在我的项目“用户”和“公司”中有两个可验证模型。 I have to different middlewares. 我必须使用不同的中间件。 one for "User" and one for "Company". 一个用于“用户”,一个用于“公司”。 and each model had its own token (saved in cookies). 每个模型都有自己的令牌(保存在Cookie中)。

This two model is related (user belongs to a company) 这两个模型是相关的(用户属于公司)

now i want to get a user and if the user belongs to Company, login the user as company too. 现在我想获得一个用户,如果该用户属于Company,则也以该公司的身份登录该用户。 it simple to do this, but i need to do this with just one token. 做到这一点很简单,但是我只需要一个令牌就可以做到这一点。 because i want to use one request and one middleware. 因为我想使用一个请求和一个中间件。

Is there any way or method that i can set user token to company. 有什么方法或方法可以将用户令牌设置为公司。 instead of get new token from company? 而不是从公司那里获得新代币?

Generally speaking, this is not proper way. 一般来说,这不是正确的方法。 User should be authenticated, and not the Company , but user belongs to company, so you can modify/access/change data, within that relationship. 应该对User进行身份验证,而不是对Company进行身份验证,但是该用户belongs to company,因此您可以在该关系中修改/访问/更改数据。

IMO, you should go that path. 海事组织,你应该走那条路。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM