mirror of
				https://github.com/louislam/uptime-kuma.git
				synced 2025-11-04 13:46:13 +08:00 
			
		
		
		
	Add loginRequired SocketIO event (#4636)
				
					
				
			This commit is contained in:
		@@ -1535,6 +1535,7 @@ let needSetup = false;
 | 
				
			|||||||
            await afterLogin(socket, await R.findOne("user"));
 | 
					            await afterLogin(socket, await R.findOne("user"));
 | 
				
			||||||
            socket.emit("autoLogin");
 | 
					            socket.emit("autoLogin");
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
 | 
					            socket.emit("loginRequired");
 | 
				
			||||||
            log.debug("auth", "need auth");
 | 
					            log.debug("auth", "need auth");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -129,6 +129,16 @@ export default {
 | 
				
			|||||||
                this.allowLoginDialog = false;
 | 
					                this.allowLoginDialog = false;
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            socket.on("loginRequired", () => {
 | 
				
			||||||
 | 
					                let token = this.storage().token;
 | 
				
			||||||
 | 
					                if (token && token !== "autoLogin") {
 | 
				
			||||||
 | 
					                    this.loginByToken(token);
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    this.$root.storage().removeItem("token");
 | 
				
			||||||
 | 
					                    this.allowLoginDialog = true;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            socket.on("monitorList", (data) => {
 | 
					            socket.on("monitorList", (data) => {
 | 
				
			||||||
                // Add Helper function
 | 
					                // Add Helper function
 | 
				
			||||||
                Object.entries(data).forEach(([ monitorID, monitor ]) => {
 | 
					                Object.entries(data).forEach(([ monitorID, monitor ]) => {
 | 
				
			||||||
@@ -256,24 +266,6 @@ export default {
 | 
				
			|||||||
                    this.clearData();
 | 
					                    this.clearData();
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                let token = this.storage().token;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                if (token) {
 | 
					 | 
				
			||||||
                    if (token !== "autoLogin") {
 | 
					 | 
				
			||||||
                        this.loginByToken(token);
 | 
					 | 
				
			||||||
                    } else {
 | 
					 | 
				
			||||||
                        // Timeout if it is not actually auto login
 | 
					 | 
				
			||||||
                        setTimeout(() => {
 | 
					 | 
				
			||||||
                            if (! this.loggedIn) {
 | 
					 | 
				
			||||||
                                this.allowLoginDialog = true;
 | 
					 | 
				
			||||||
                                this.$root.storage().removeItem("token");
 | 
					 | 
				
			||||||
                            }
 | 
					 | 
				
			||||||
                        }, 5000);
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                } else {
 | 
					 | 
				
			||||||
                    this.allowLoginDialog = true;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                this.socket.firstConnect = false;
 | 
					                this.socket.firstConnect = false;
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user