Move sessions to db table instead of JWTs

This commit is contained in:
Andrew Glaze
2025-05-23 11:52:06 -04:00
parent 62260ffc73
commit 49cd62da1d
11 changed files with 114 additions and 101 deletions

View File

@@ -88,7 +88,7 @@ final class Player: Model, @unchecked Sendable {
account: Account,
tutorialStep: Int?,
tutorialSkipFlag: Int?
) {
) throws {
self.stamina = stamina
self.staminaHealTime = staminaHealTime
self.boostPoint = boostPoint
@@ -114,10 +114,12 @@ final class Player: Model, @unchecked Sendable {
self.enableAuto3x = enableAuto3x
self.tutorialStep = tutorialStep
self.tutorialSkipFlag = tutorialSkipFlag
self.$account.id = try account.requireID()
}
static func createDefault(account: Account) -> Player {
return Player(
static func createDefault(account: Account) throws -> Player {
return try Player(
stamina: 20,
staminaHealTime: Date.now,
boostPoint: 3,

View File

@@ -0,0 +1,32 @@
import Fluent
final class Session: Model, @unchecked Sendable {
static let schema: String = "sessions"
@ID(custom: "token", generatedBy: .random)
var id: String?
@Parent(key: "accountId")
var account: Account
@Field(key: "expires")
var expires: Date
@Field(key: "type")
var type: SessionType
init() { }
init(account: Account, expires: Date, type: SessionType) throws {
self.id = UUID().uuidString
self.$account.id = try account.requireID()
self.expires = expires
self.type = type
}
}
enum SessionType: Int, Codable {
case ZAT = 0
case ZRT = 1
case VIEWER = 2
}