'devise gem allows you to have multiple models signed in at the same time what that mean?
I am new to Rails and I came across this devise gem can you tell what this line means "devise gem allows you to have multiple models signed"?
Solution 1:[1]
Devise is built on top of the Warden gem which is the part that actually does the grunt work of authenticating users and storing the claims in the session.
Warden accepts a scope argument both when storing users in the session and retrieving them. An very simplefied example of the concept is that:
# This code won't actually run as Warden is used as part of the
# rack stack when dealing with HTTP requests
warden = env['warden']
admin = Admin.create!(email: '[email protected]', password: 'p4ssword')
user = User.create!(email: '[email protected]', password: 'p4ssword')
warden.set_user(admin, scope: :admin)
warden.set_user(user, scope: :user)
warden.authenticate(:password, :admin).user == admin
warden.authenticate(:password, :user).user == user
Whats happening when you call warden.set_user(admin, scope: :admin) is that its saving the id of the record into the session and using the scope as part of the key so that you can store different ids for different scopes. Thus having "different users signed in at the same time".
Devise actually sets the Warden scopes based on the arguments passed to devise_for in your routes file. If you call devise_for :users then the scope is :user.
This isn't really a feature that you you need to use or know about as a beginner since you're just using a single scope most of the time anyways.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
