ToolJet/lib/json_web_token.rb
2021-04-16 12:00:09 +05:30

15 lines
No EOL
372 B
Ruby

class JsonWebToken
class << self
def encode(payload, exp = 24.hours.from_now)
payload[:exp] = exp.to_i
JWT.encode(payload, ENV.fetch("SECRET_KEY_BASE"))
end
def decode(token)
body = JWT.decode(token, ENV.fetch("SECRET_KEY_BASE"))[0]
HashWithIndifferentAccess.new body
rescue
nil
end
end
end