create basic backend with login

This commit is contained in:
2026-09-21 21:43:30 +03:00
commit e1c4a5b9ba
79 changed files with 2834 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
class JwtService
SECRET_KEY = Rails.application.secret_key_base
ALGORITHM = "HS256"
EXPIRATION = 7.days
def self.encode(payload)
payload[:exp] = EXPIRATION.from_now.to_i
JWT.encode(payload, SECRET_KEY, ALGORITHM)
end
def self.decode(token)
decoded = JWT.decode(token, SECRET_KEY, true, { algorithm: ALGORITHM }).first
HashWithIndifferentAccess.new(decoded).slice(:user_id, :exp)
rescue JWT::DecodeError, JWT::ExpiredSignature
nil
end
end