{"version":3,"sources":["../../../src/lib/use-security-settings.tsx"],"sourcesContent":["import {\n  AuthenticationInformationResponse,\n  getAuthenticationInformationQueryKey,\n} from \"../api/endpoint.js\";\nimport { useQueryClient } from \"@tanstack/react-query\";\n\ntype Methods = \"Password\" | \"Mfa\" | \"Passkey\";\n\n/**\n * A hook that provides utilities for managing security settings.\n * Allows optimistically updating verification method status (password, MFA, passkey)\n * while also triggering a server revalidation.\n */\nexport function useSecuritySettings() {\n  const client = useQueryClient();\n\n  const update = (method: Methods, isSetUp: boolean) => {\n    const queryKey = getAuthenticationInformationQueryKey();\n\n    // Optimistic update\n    client.setQueriesData<AuthenticationInformationResponse>(\n      { queryKey, exact: false },\n      (data) => {\n        if (!data) {\n          return data;\n        }\n\n        return {\n          ...data,\n          data: {\n            ...data.data,\n            verificationMethods: {\n              ...data.data.verificationMethods,\n              [method]: { ...data.data.verificationMethods[method], isSetUp },\n            },\n          },\n        };\n      },\n    );\n\n    // Also validate it with the server\n    client.invalidateQueries({\n      queryKey: getAuthenticationInformationQueryKey(),\n      exact: false,\n    });\n  };\n\n  return { update };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAGO;AACP,yBAA+B;AASxB,SAAS,sBAAsB;AACpC,QAAM,aAAS,mCAAe;AAE9B,QAAM,SAAS,CAAC,QAAiB,YAAqB;AACpD,UAAM,eAAW,sDAAqC;AAGtD,WAAO;AAAA,MACL,EAAE,UAAU,OAAO,MAAM;AAAA,MACzB,CAAC,SAAS;AACR,YAAI,CAAC,MAAM;AACT,iBAAO;AAAA,QACT;AAEA,eAAO;AAAA,UACL,GAAG;AAAA,UACH,MAAM;AAAA,YACJ,GAAG,KAAK;AAAA,YACR,qBAAqB;AAAA,cACnB,GAAG,KAAK,KAAK;AAAA,cACb,CAAC,MAAM,GAAG,EAAE,GAAG,KAAK,KAAK,oBAAoB,MAAM,GAAG,QAAQ;AAAA,YAChE;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAGA,WAAO,kBAAkB;AAAA,MACvB,cAAU,sDAAqC;AAAA,MAC/C,OAAO;AAAA,IACT,CAAC;AAAA,EACH;AAEA,SAAO,EAAE,OAAO;AAClB;","names":[]}