Compare commits

...

2 Commits

2 changed files with 35 additions and 13 deletions

View File

@@ -46,8 +46,13 @@ export const RegisterPage: FC = () => {
const { t } = useTranslation();
usePageTitle(t("action.register"));
const { loading, authenticated, passwordlessUser, client, setClient } =
useClientLegacy();
const {
loading,
authenticated,
passwordlessUser: previousClientPasswordlessUser,
client: previousClient,
setClient,
} = useClientLegacy();
const confirmPasswordRef = useRef<HTMLInputElement>(null);
const history = useHistory();
@@ -56,7 +61,7 @@ export const RegisterPage: FC = () => {
const [error, setError] = useState<Error>();
const [password, setPassword] = useState("");
const [passwordConfirmation, setPasswordConfirmation] = useState("");
const { recaptchaKey, register } = useInteractiveRegistration();
const { recaptchaKey, register } = useInteractiveRegistration(previousClient);
const { execute, reset, recaptchaId } = useRecaptcha(recaptchaKey);
const onSubmitRegisterForm = useCallback(
@@ -78,12 +83,16 @@ export const RegisterPage: FC = () => {
password,
userName,
recaptchaResponse,
passwordlessUser,
false,
);
if (client && client?.groupCallEventHandler && passwordlessUser) {
if (
previousClient &&
previousClient?.groupCallEventHandler &&
previousClientPasswordlessUser
) {
// Migrate the user's rooms
for (const groupCall of client.groupCallEventHandler.groupCalls.values()) {
for (const groupCall of previousClient.groupCallEventHandler.groupCalls.values()) {
const roomId = groupCall.room.roomId;
try {
@@ -130,10 +139,10 @@ export const RegisterPage: FC = () => {
register,
location,
history,
passwordlessUser,
previousClientPasswordlessUser,
reset,
execute,
client,
previousClient,
setClient,
],
);
@@ -149,10 +158,21 @@ export const RegisterPage: FC = () => {
}, [password, passwordConfirmation, t]);
useEffect(() => {
if (!loading && authenticated && !passwordlessUser && !registering) {
if (
!loading &&
authenticated &&
!previousClientPasswordlessUser &&
!registering
) {
history.push("/");
}
}, [loading, history, authenticated, passwordlessUser, registering]);
}, [
loading,
history,
authenticated,
previousClientPasswordlessUser,
registering,
]);
if (loading) {
return <LoadingView />;

View File

@@ -27,7 +27,9 @@ import { Session } from "../ClientContext";
import { Config } from "../config/Config";
import { widget } from "../widget";
export const useInteractiveRegistration = (): {
export const useInteractiveRegistration = (
oldClient?: MatrixClient,
): {
privacyPolicyUrl?: string;
recaptchaKey?: string;
register: (
@@ -105,7 +107,7 @@ export const useInteractiveRegistration = (): {
/* eslint-disable camelcase,@typescript-eslint/no-explicit-any */
const { user_id, access_token, device_id } =
(await interactiveAuth.attemptAuth()) as any;
await oldClient?.logout(true);
const client = await initClient(
{
baseUrl: Config.defaultHomeserverUrl()!,
@@ -136,7 +138,7 @@ export const useInteractiveRegistration = (): {
return [client, session];
},
[],
[oldClient],
);
return { privacyPolicyUrl, recaptchaKey, register };