Move sessions to db table instead of JWTs
This commit is contained in:
32
Sources/stella/Models/Session.swift
Normal file
32
Sources/stella/Models/Session.swift
Normal 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
|
||||
}
|
Reference in New Issue
Block a user