session handling for players and hosts

This commit is contained in:
2025-05-17 12:23:19 -06:00
parent fee5576efd
commit b6a4936247
11 changed files with 221 additions and 28 deletions
+21
View File
@@ -0,0 +1,21 @@
import gleam/dynamic/decode
import gleam/json
pub type PlayerSession {
PlayerSession(id: Int, token_hash: String, username: String)
}
pub fn encode_player_session(player_session: PlayerSession) -> json.Json {
json.object([
#("id", json.int(player_session.id)),
#("token_hash", json.string(player_session.token_hash)),
#("username", json.string(player_session.username)),
])
}
pub fn player_session_decoder() -> decode.Decoder(PlayerSession) {
use id <- decode.field("id", decode.int)
use token_hash <- decode.field("token_hash", decode.string)
use username <- decode.field("username", decode.string)
decode.success(PlayerSession(id:, token_hash:, username:))
}