Reset auth when connection closes
This commit is contained in:
@@ -37,6 +37,7 @@ export class ConnectionAuth {
|
||||
|
||||
constructor(readonly connection: Connection) {
|
||||
this.connection.on('receive', this.#onReceive)
|
||||
this.connection.on('close', this.#onClose)
|
||||
}
|
||||
|
||||
#onReceive = (connection: Connection, message: SocketMessage) => {
|
||||
@@ -63,6 +64,13 @@ export class ConnectionAuth {
|
||||
}
|
||||
}
|
||||
|
||||
#onClose = (connection: Connection) => {
|
||||
this.challenge = undefined
|
||||
this.request = undefined
|
||||
this.message = undefined
|
||||
this.status = None
|
||||
}
|
||||
|
||||
attempt = async () => {
|
||||
if (!this.challenge) {
|
||||
throw new Error("Attempted to authenticate with no challenge")
|
||||
@@ -124,6 +132,7 @@ export class ConnectionAuth {
|
||||
}
|
||||
|
||||
destroy = () => {
|
||||
this.connection.off('recieve', this.#onReceive)
|
||||
this.connection.off('receive', this.#onReceive)
|
||||
this.connection.off('close', this.#onClose)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user