Skip to content

Commit

Permalink
Trigger handleSwitchChange when user logged in
Browse files Browse the repository at this point in the history
  • Loading branch information
eunjuhuss committed Sep 3, 2024
1 parent a48f429 commit 15e0430
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/components/Dashboard/UseSecurityKeyToggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { postSecurityKeyPreference, PreferencesData } from "apis/eduidPersonalDa
import { useAppDispatch, useAppSelector } from "eduid-hooks";
import { useEffect, useState } from "react";
import { FormattedMessage } from "react-intl";
import authnSlice from "slices/Authn";
import { AuthenticateModal } from "./Authenticate";

export default function UseSecurityKeyToggle(): JSX.Element | null {
Expand All @@ -11,12 +12,20 @@ export default function UseSecurityKeyToggle(): JSX.Element | null {
);
const [showAuthnModal, setShowAuthnModal] = useState(false);
const [switchChecked, setSwitchChecked] = useState(always_use_security_key);
const frontend_action = useAppSelector((state: any) => state.authn.frontend_action);

useEffect(() => {
setSwitchChecked(always_use_security_key);
}, [always_use_security_key]);

useEffect(() => {
if (frontend_action === "changeSecurityPreferencesAuthn") {
handleSwitchChange();
}
}, [frontend_action]);

async function handleSwitchChange() {
dispatch(authnSlice.actions.setFrontendActionState());
setSwitchChecked(!switchChecked);
if (switchChecked !== undefined) {
const response = await dispatch(postSecurityKeyPreference({ always_use_security_key: !switchChecked }));
Expand Down

0 comments on commit 15e0430

Please sign in to comment.