Module: Devise::Models::MagicLinkAuthenticatable

Extended by:
ActiveSupport::Concern
Defined in:
lib/devise/models/magic_link_authenticatable.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

Set this to false to disable magic link auth for this model instance. Magic links will still be generated by the sign-in page, but visiting them will instead display an error message.

Returns:

  • (Boolean)


57
58
59
# File 'lib/devise/models/magic_link_authenticatable.rb', line 57

def active_for_magic_link_authentication?
  true
end

A callback initiated after successfully authenticating. This can be used to insert your own logic that is only run after the user successfully authenticates.

Example:

def after_magic_link_authentication
  self.update_attribute(:invite_code, nil)
end


51
52
# File 'lib/devise/models/magic_link_authenticatable.rb', line 51

def after_magic_link_authentication
end

#encode_passwordless_token(*args, **kwargs) ⇒ Object



32
33
34
# File 'lib/devise/models/magic_link_authenticatable.rb', line 32

def encode_passwordless_token(*args, **kwargs)
  self.class.passwordless_tokenizer_class.encode(self, *args, **kwargs)
end

This method determines which error message to display when magic link auth is disabled for this model instance.



63
64
65
# File 'lib/devise/models/magic_link_authenticatable.rb', line 63

def magic_link_inactive_message
  :magic_link_invalid
end

#passwordObject

Not having a #password method breaks the :validatable module

NOTE I proposed a change to Devise to fix this: github.com/heartcombo/devise/issues/5346#issuecomment-822022834 As of yet it hasn’t been accepted due to unknowns of the legacy code’s purpose



27
28
29
# File 'lib/devise/models/magic_link_authenticatable.rb', line 27

def password
  nil
end

#password_required?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/devise/models/magic_link_authenticatable.rb', line 16

def password_required?
  false
end


36
37
38
39
# File 'lib/devise/models/magic_link_authenticatable.rb', line 36

def send_magic_link(remember_me: false, **kwargs)
  token = self.encode_passwordless_token
  send_devise_notification(:magic_link, token, remember_me, **kwargs)
end