Skip to content
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions src/server/Worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,19 +282,30 @@ export async function startWorker() {
return;
}

// Verify token signature
const result = await verifyClientToken(clientMsg.token, config);
if (result.type === "error") {
log.warn(`Invalid token: ${result.message}`, {
clientID: clientMsg.clientID,
});
ws.close(
1002,
`Unauthorized: invalid token for client ${clientMsg.clientID}`,
);
return;
// Verify token signature (skip in dev mode)
const isDev = process.env.GAME_ENV === "dev";
Comment thread
ryanbarlow97 marked this conversation as resolved.
Outdated
let persistentId: string;
let claims: any;
Comment thread
ryanbarlow97 marked this conversation as resolved.
Outdated

if (!isDev) {
const result = await verifyClientToken(clientMsg.token, config);
if (result.type === "error") {
log.warn(`Invalid token: ${result.message}`, {
clientID: clientMsg.clientID,
});
ws.close(
1002,
`Unauthorized: invalid token for client ${clientMsg.clientID}`,
);
return;
}
persistentId = result.persistentId;
claims = result.claims;
} else {
// In dev mode, use clientID as persistentId
persistentId = clientMsg.clientID;
claims = null;
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
const { persistentId, claims } = result;

if (clientMsg.type === "rejoin") {
log.info("rejoining game", {
Expand Down Expand Up @@ -323,8 +334,8 @@ export async function startWorker() {
ws.close(1002, "Unauthorized");
return;
}
} else {
// Verify token and get player permissions
} else if (!isDev) {
Comment thread
ryanbarlow97 marked this conversation as resolved.
Outdated
// Verify token and get player permissions (skip in dev mode)
Comment thread
ryanbarlow97 marked this conversation as resolved.
Outdated
const result = await getUserMe(clientMsg.token, config);
if (result.type === "error") {
log.warn(`Unauthorized: ${result.message}`, {
Expand Down
Loading