Admins have 6 hours JWT expiration instead of 24
This commit is contained in:
parent
569d9488ae
commit
ae5823ca46
|
@ -11,7 +11,7 @@ module Backend
|
|||
JWT.encode({"data" => data.to_h, "exp" => expiration}, Backend.config.api.jwt_secret, JWT::Algorithm::HS256)
|
||||
end
|
||||
|
||||
def create_user_jwt(user_id : Int, expiration : Int = (Time.utc + Time::Span.new(days: 1)).to_unix) : String
|
||||
def create_user_jwt(user_id : Int, expiration : Int) : String
|
||||
create_jwt({user_id: user_id}, expiration)
|
||||
end
|
||||
|
||||
|
|
|
@ -14,7 +14,10 @@ module Backend
|
|||
|
||||
LoginPayload.new(
|
||||
user: User.new(user),
|
||||
token: Auth.create_user_jwt(user.id.not_nil!.to_i),
|
||||
token: Auth.create_user_jwt(
|
||||
user.id.not_nil!.to_i,
|
||||
(Time.utc + (user.admin ? Time::Span.new(hours: 6) : Time::Span.new(days: 1))).to_unix
|
||||
),
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -59,8 +59,6 @@ module Backend
|
|||
puts "Role: #{user.role}"
|
||||
puts "Admin: #{user.admin}"
|
||||
puts "---"
|
||||
puts "Token: #{Api::Auth.create_user_jwt(user_id: user.id.not_nil!)}"
|
||||
puts "---"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue