Following is the create action of DeviseTokenAuth Sessions Controller.
def create
field = (resource_params.keys.map(&:to_sym) & resource_class.authentication_keys).first
@resource = nil
if field
email_value = get_case_insensitive_field_from_resource_params(field)
@resource = find_resource(field, email_value)
end
if @resource && valid_params?(field, email_value) && @resource.active_for_authentication? #this return true
debugger
valid_password = @resource.valid_password?(resource_params[:password])
if (@resource.respond_to?(:valid_for_authentication?) && !@resource.valid_for_authentication? { valid_password }) || !valid_password
return render_create_error_bad_credentials
end
debugger
@token = @resource.create_token
@resource.save
sign_in(:user, @resource, store: false, bypass: false)
yield @resource if block_given?
render_create_success
elsif @resource && !(@resource.active_for_authentication?)
if @resource.respond_to?(:locked_at) && @resource.locked_at
render_create_error_account_locked
else
render_create_error_not_confirmed
end
else
render_create_error_bad_credentials
end
end
I am using postman, for now if a user is signed in and again tries to sign in , it goes and sign in again and create token again. I want if a user is signed in, token should not generated again and again