README.md in devise-guests-0.8.0 vs README.md in devise-guests-0.8.1
- old
+ new
@@ -1,6 +1,7 @@
# Devise Guests
+[](https://badge.fury.io/rb/devise-guests)
[](https://github.com/cbeer/devise-guests/actions/workflows/tests.yml)
[](https://github.com/testdouble/standard)
A drop-in guest user implementation for devise
@@ -39,18 +40,15 @@
```
### Transferring Guest to User on Login
During the login process you may want to transfer things from your guest user to the account the logged into.
-To do so, modify your ApplicationController like so:
+To do so, add the following method to your ApplicationController:
```ruby
-define_callbacks :logging_in_user
-set_callback :logging_in_user, :before, :transfer_guest_to_current_user
-
private
-def transfer_guest_to_current_user
+def transfer_guest_to_user
# At this point you have access to:
# * current_user - the user they've just logged in as
# * guest_user - the guest user they were previously identified by
#
# After this block runs, the guest_user will be destroyed!
@@ -72,9 +70,29 @@
private
def guest_user_params
{ site_id: current_site.id }
end
```
+
+### Non-standard authentication keys
+
+By default Devise will use `:email` as the authentication key for your model. If for some reason you have modified your
+Devise config to use an alternative attribute (such as `:phone_number`) you will need to provide a method to generate
+the value of this attribute for any guest users which are created.
+
+Sticking with the `:phone_number` example, you should define the following method in your `application_controller.rb`:
+
+```ruby
+private
+def guest_phone_number_authentication_key(key)
+ key &&= nil unless key.to_s.match(/^guest/)
+ key ||= "guest_447" + 9.times.map { SecureRandom.rand(0..9) }.join
+end
+```
+
+Validations are skipped when creating guest users, but if you need to rely on future modifications to the guest record
+passing validations, then you should ensure that this default value for guests is generated in such a way as to be
+valid.
### Prevent deletion of guest records
By default, when signing in from a guest account to an authenticated account, the guest user is destroyed. You have an
opportunity through the `logging_in_user` callback (or `logging_in_MODEL` if you're not using `User`) to transfer data