ToolJet/lib/json_web_token.rb

15 lines
372 B
Ruby
Raw Normal View History

2021-03-31 16:18:42 +00:00
class JsonWebToken
class << self
def encode(payload, exp = 24.hours.from_now)
payload[:exp] = exp.to_i
2021-04-16 06:30:09 +00:00
JWT.encode(payload, ENV.fetch("SECRET_KEY_BASE"))
2021-03-31 16:18:42 +00:00
end
def decode(token)
2021-04-16 06:30:09 +00:00
body = JWT.decode(token, ENV.fetch("SECRET_KEY_BASE"))[0]
2021-03-31 16:18:42 +00:00
HashWithIndifferentAccess.new body
rescue
nil
end
end
end