Terminate on auth token 403 or 401

Former-commit-id: 63f0a28b77
This commit is contained in:
Owen
2025-11-30 18:12:06 -05:00
parent 672fff0ad9
commit 9ce6450351
3 changed files with 62 additions and 0 deletions

View File

@@ -799,6 +799,24 @@ func StartTunnel(config TunnelConfig) {
}
})
olm.OnAuthError(func(statusCode int, message string) {
logger.Error("Authentication error (status %d): %s. Terminating tunnel.", statusCode, message)
apiServer.SetTerminated(true)
apiServer.SetConnectionStatus(false)
apiServer.SetRegistered(false)
apiServer.ClearPeerStatuses()
network.ClearNetworkSettings()
Close()
if globalConfig.OnAuthError != nil {
go globalConfig.OnAuthError(statusCode, message)
}
if globalConfig.OnTerminated != nil {
go globalConfig.OnTerminated()
}
})
// Connect to the WebSocket server
if err := olm.Connect(); err != nil {
logger.Error("Failed to connect to server: %v", err)

View File

@@ -45,6 +45,7 @@ type GlobalConfig struct {
OnRegistered func()
OnConnected func()
OnTerminated func()
OnAuthError func(statusCode int, message string) // Called when auth fails (401/403)
// Source tracking (not in JSON)
sources map[string]string