-
-
Notifications
You must be signed in to change notification settings - Fork 88
Usage with Sidekiq::Web
Mikkel Malmberg edited this page Jun 19, 2023
·
1 revision
Sidekiq docs does not (yet) feature an example for Passwordless, but their restful authentication or sorcery example is pretty close to a working solution. This is how I did it:
# app/models/user.rb
class User < ApplicationRecord
validates :email, presence: true, uniqueness: { case_sensitive: false }
passwordless_with :email
# Treating all users as admins to make the example short. This part will likely look different in your app ✌️
def admin?
true
end
end
# lib/admin_constraint.rb
class AdminConstraint
def matches?(request)
passwordless_session_id = request.session['passwordless_session_id--user']
return false unless passwordless_session_id
user = Passwordless::Session.find(passwordless_session_id).authenticatable
user&.admin?
end
end
# config/routes.rb
require 'sidekiq/web'
require 'admin_constraint'
Rails.application.routes.draw do
passwordless_for :users
mount Sidekiq::Web => '/sidekiq', constraints: AdminConstraint.new
...
end