Class: Clerk::SessionToken

Inherits:
ApplicationRecord show all
Defined in:
app/models/clerk/session_token.rb

Class Method Summary collapse

Methods inherited from ApplicationRecord

clerk_table_name, clerk_table_name_nc, transaction

Class Method Details

.find_account(cookie:) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/models/clerk/session_token.rb', line 8

def self.(cookie:)
  require "bcrypt"
  begin
    id, token, token_hash = Clerk.decrypt(cookie).split("--")
    if BCrypt::Password.new(token_hash) == token
      Account.joins(:session_token).where(token_hash: token_hash, )
      SessionToken.eager_load(:account).find_by!(id: id, token_hash: token_hash)&.
    else 
      nil
    end
  rescue => e
    puts "Error finding acount #{e}"
    puts "Cookie #{cookie}"
    nil
  end
end