Move sessions to db table instead of JWTs
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import Vapor
|
||||
import JWT
|
||||
import Fluent
|
||||
|
||||
struct OpenApiController: RouteCollection {
|
||||
func boot(routes: any RoutesBuilder) throws {
|
||||
@@ -17,10 +17,13 @@ struct OpenApiController: RouteCollection {
|
||||
guard let zatToken = req.headers["zat"].first else {
|
||||
throw Abort(.badRequest, reason: "Missing zat header.")
|
||||
}
|
||||
let jwt = try await req.jwt.verify(zatToken, as: SessionPayload.self)
|
||||
guard jwt.accountId.value == beat.playerId else {
|
||||
|
||||
guard let session = try await Session.query(on: req.db).filter(\.$id == zatToken).first(),
|
||||
let playerId = Int(beat.playerId),
|
||||
session.$account.id == playerId else {
|
||||
throw Abort(.unauthorized, reason: "zat invalid")
|
||||
}
|
||||
|
||||
return "{}"
|
||||
}
|
||||
|
||||
@@ -29,8 +32,9 @@ struct OpenApiController: RouteCollection {
|
||||
guard let zatToken = req.headers["zat"].first else {
|
||||
throw Abort(.badRequest, reason: "Missing zat header.")
|
||||
}
|
||||
let jwt = try await req.jwt.verify(zatToken, as: SessionPayload.self)
|
||||
guard jwt.accountId.value == beat.playerId else {
|
||||
guard let session = try await Session.query(on: req.db).filter(\.$id == zatToken).first(),
|
||||
let playerId = Int(beat.playerId),
|
||||
session.$account.id == playerId else {
|
||||
throw Abort(.unauthorized, reason: "zat invalid")
|
||||
}
|
||||
return "{}"
|
||||
|
Reference in New Issue
Block a user