-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathuser.rb
More file actions
27 lines (20 loc) · 1.09 KB
/
user.rb
File metadata and controls
27 lines (20 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class User < ApplicationRecord
devise :cognito_authenticatable, :timeoutable
attr_accessor :access_token
# == Enums ========================================================
# See `technical-foundation.md#enums` for important note about enums.
enum :mfa_preference, { opt_out: 0, software_token: 1 }, validate: { allow_nil: true }
# == Relationships ========================================================
has_many :tasks
# == Validations ==========================================================
validates :provider, presence: true
# == Methods ==============================================================
# Check if the access token is expired or will expire within the next `minutes` minutes.
# Access token is only stored in the session, so it needs passed in, rather than accessed from the model.
def access_token_expires_within_minutes?(access_token, minutes)
return true unless access_token.present?
decoded_token = JWT.decode(access_token, nil, false)
expiration_time = Time.at(decoded_token.first["exp"])
expiration_time < Time.now + minutes.minutes
end
end