blob: beab467fe5951691d5871378bb8b97f77fd9cad9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# frozen_string_literal: true
# Common logic for all the logics that require the token generation
# service.
module TokenGenerationConcern
extend ActiveSupport::Concern
def service
@service ||= Services::TokenGenerationService.new(service_params)
end
def generate_user_session_key(user)
user.update_attribute(:session_key, SecureRandom.hex(16))
end
def generate_token
{ token: service.call(DateTime.current + 30.minutes), refresh: service.call(DateTime.current + 3.days) }
end
def service_params
{ email: @user_account.email, role: @user_account.role, session_key: @user_account.session_key }
end
end
|