Module: Koi::Controller::JsonWebToken

Extended by:
ActiveSupport::Concern
Included in:
Admin::TokensController
Defined in:
app/controllers/concerns/koi/controller/json_web_token.rb

Constant Summary collapse

SECRET_KEY =
Rails.application.secret_key_base

Instance Method Summary collapse

Instance Method Details

#decode_token(token) ⇒ Object



14
15
16
17
18
19
# File 'app/controllers/concerns/koi/controller/json_web_token.rb', line 14

def decode_token(token)
  payload = JWT.decode(token, SECRET_KEY)[0]
  ActiveSupport::HashWithIndifferentAccess.new(payload)
rescue JWT::DecodeError
  nil
end

#encode_token(**payload) ⇒ Object



10
11
12
# File 'app/controllers/concerns/koi/controller/json_web_token.rb', line 10

def encode_token(**payload)
  JWT.encode(payload, SECRET_KEY)
end