Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix race condition of disconnecting during auth (#169) #170

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Changes from all 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
6 changes: 5 additions & 1 deletion packages/3d-web-user-networking/src/UserNetworkingServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ export class UserNetworkingServer {
if (!client.authenticatedUser) {
if (parsed.type === USER_NETWORKING_USER_AUTHENTICATE_MESSAGE_TYPE) {
this.handleUserAuth(client, parsed).then((authResult) => {
if (client.socket.readyState !== WebSocketOpenStatus) {
// The client disconnected before the authentication was completed
return;
}
if (!authResult) {
// If the user is not authorized, disconnect the client
const serverError = JSON.stringify({
Expand All @@ -147,6 +151,7 @@ export class UserNetworkingServer {
}

const userData = authResult;
client.authenticatedUser = userData;

// Give the client its own profile
const userProfileMessage = JSON.stringify({
Expand Down Expand Up @@ -262,7 +267,6 @@ export class UserNetworkingServer {
}

console.log("Client authenticated", client.id, resolvedUserData);
client.authenticatedUser = resolvedUserData;

return resolvedUserData;
}
Expand Down
Loading