I have a goal to have a User model and a Vendor model. Think as if User is a company, and Vendor is employees where the company can create multiple employee accounts to associate to the company.
I have set up Sorcery to have User model and Vendor model but when signing in is where my issues are.
At the end of the sorcery file, there is this:
config.user_class = "User"
I have tried:
config.user_class = "User" || "Vendor"
When signing in, it will only search through the model that is first. this:
config.user_class = "User"
config.user_class = "Vendor"
(in both orders, vice versa) Whichever is last, that model works. It will search only through the Vendor model if the Vendor model is last.
I looked into STI, but most of what I have seen is creating associated models that inherit from the one model. Not much on multiple models for authentication for each, or any. Is this a route to go into?
I need both User and Vendor to be able to sign in as separate accounts.
I have, in the past, used Devise to create multiple models with ease but Sorcery seems to be giving issues?
Is there a way to set up Sorcery to allow multiple models?
Sorcery does allow STI though the user.subclasses_inherit_config
setting in config/initializers/sorcery.rb
. You can set it to true
then inherit your Vendor class from User.
I've never used the Gem but I would look at just adding a role to your user class and use authorization.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.