Skip to content

Commit

Permalink
Fix (registration flow): logout old before creating new client as req…
Browse files Browse the repository at this point in the history
…uired by initClient. (#2604)
  • Loading branch information
toger5 authored Sep 2, 2024
1 parent 5f8081b commit 922fe5b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/auth/RegisterPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,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(client);
const { execute, reset, recaptchaId } = useRecaptcha(recaptchaKey);

const onSubmitRegisterForm = useCallback(
Expand Down
8 changes: 5 additions & 3 deletions src/auth/useInteractiveRegistration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: (
Expand Down Expand Up @@ -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()!,
Expand Down Expand Up @@ -136,7 +138,7 @@ export const useInteractiveRegistration = (): {

return [client, session];
},
[],
[oldClient],
);

return { privacyPolicyUrl, recaptchaKey, register };
Expand Down

0 comments on commit 922fe5b

Please sign in to comment.