Move sessions to db table instead of JWTs
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import Vapor
|
||||
import Fluent
|
||||
import SwiftMsgpack
|
||||
import JWT
|
||||
|
||||
@@ -13,11 +14,24 @@ struct ToolController: RouteCollection {
|
||||
func signup(req: Request) async throws -> Response {
|
||||
let body = try req.content.decode(SignupReq.self, using: MsgPackDecoder())
|
||||
|
||||
let session = try await req.jwt.verify(body.access_token, as: SessionPayload.self)
|
||||
guard session.type == SessionType.ZAT.rawValue else {
|
||||
guard
|
||||
let session = try await Session.query(on: req.db).filter(\.$id == body.access_token).first(),
|
||||
session.type == SessionType.ZAT
|
||||
else {
|
||||
throw Abort(.forbidden, reason: "Invalid access token")
|
||||
}
|
||||
let accountId = session.$account.id
|
||||
|
||||
if let player = try await Player.query(on: req.db).filter(\.$account.$id == accountId).first() {
|
||||
|
||||
} else {
|
||||
guard let account = try await Account.query(on: req.db).filter(\.$id == accountId).first() else {
|
||||
throw Abort(.forbidden, reason: "Account ID does not exist")
|
||||
}
|
||||
// Create new Player
|
||||
let player = try Player.createDefault(account: account)
|
||||
try await player.save(on: req.db)
|
||||
}
|
||||
|
||||
throw Abort(.notImplemented)
|
||||
}
|
||||
|
Reference in New Issue
Block a user