diff --git a/src/components/structures/auth/Registration.tsx b/src/components/structures/auth/Registration.tsx index c5abe526f6..ff7e41b9d5 100644 --- a/src/components/structures/auth/Registration.tsx +++ b/src/components/structures/auth/Registration.tsx @@ -139,8 +139,21 @@ export default class Registration extends React.Component { componentDidMount() { this.replaceClient(this.props.serverConfig); + //triggers a confirmation dialog for data loss before page unloads/refreshes + window.addEventListener("beforeunload", this.unloadCallback); } + componentWillUnmount() { + window.removeEventListener("beforeunload", this.unloadCallback); + } + + private unloadCallback = (event: BeforeUnloadEvent) => { + if (this.state.doingUIAuth) { + event.preventDefault(); + event.returnValue = ""; + return ""; + } + }; // TODO: [REACT-WARNING] Replace with appropriate lifecycle event // eslint-disable-next-line UNSAFE_componentWillReceiveProps(newProps) {