Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Devise custom authentication without a password

In my app I need to have a database authentication but without a password. Just by entering your phone number. When the user sings up he enter phone number, adress and name and no password.

Is it real? Just can't figure out how to make it.

Thanks for help in advance!

like image 848
nxxn Avatar asked Jan 19 '23 10:01

nxxn


1 Answers

Figured out like this:

In devise_no_pass.rb initializer add:

require 'devise/strategies/authenticatable'

module Devise
  module Strategies
    class DeviseNoPass < Authenticatable
      def authenticate!
        return super unless params[:customer_sign_in]
        customer = Customer.find_by_phone(params[:customer_sign_in]
        customer ? success!(customer) : raise
      end
    end
  end
end

Warden::Strategies.add(:devise_no_pass, Devise::Strategies::DeviseNoPass)

In devise.rb:

    config.warden do |manager|
      manager.default_strategies(:scope => :customer).unshift :devise_no_pass
    end
like image 62
nxxn Avatar answered Jan 29 '23 00:01

nxxn