{"version":3,"file":"WebAuthnHandler-CzvZv726.js","sources":["../../../resources/js/Pages/Auth/Helpers/WebAuthnHandler.jsx"],"sourcesContent":["import React, { useEffect, useState } from \"react\";\nimport Button from \"@/Components/Button\";\nimport { Transition } from \"@headlessui/react\";\nimport { router } from \"@inertiajs/react\";\nimport Alert from \"@/Components/Alert\";\nimport { startAuthentication } from \"@simplewebauthn/browser\";\nimport axios from \"@/Utils/axios\";\n\nconst WebAuthnHandler = ({ show }) => {\n const [error, setError] = useState(null);\n\n const webAuthnError = {\n type: \"danger\",\n message: \"Passkey authentication failed.\",\n };\n\n const handleLogin = async (event, autoFill = false) => {\n let asseResp;\n\n const request = await axios.post(route(\"webauthn.challenge\"), {});\n\n const options = request.data;\n options.allowCredentials = [];\n\n try {\n // Pass the options to the authenticator and wait for a response\n asseResp = await startAuthentication({\n optionsJSON: options,\n useBrowserAutofill: autoFill,\n });\n } catch (error) {\n // Some basic error handling\n if (error.name !== \"AbortError\") {\n console.error(error);\n setError({ ...webAuthnError, message: error.message });\n }\n return;\n }\n\n // POST the response to the endpoint that calls\n // @simplewebauthn/server -> verifyAuthenticationResponse()\n let verificationResponse;\n try {\n verificationResponse = await axios.post(\n route(\"webauthn.verify\"),\n asseResp,\n );\n } catch (error) {\n // Some basic error handling\n console.log(error);\n setError({ ...webAuthnError, message: error.message });\n return;\n }\n\n if (verificationResponse.data.success) {\n router.visit(verificationResponse.data.redirect_url);\n } else {\n setError({\n ...webAuthnError,\n message: verificationResponse.data.message,\n });\n // console.error(error);\n }\n };\n\n useEffect(() => {\n (async () => {\n await handleLogin(null, true);\n })();\n }, []);\n\n return (\n <>\n \n
\n {error && (\n \n {error.message}\n \n )}\n\n \n Sign in with passkey\n \n\n
\n
\n
\n
\n
\n \n Or use your password\n \n
\n
\n
\n \n \n );\n};\n\nexport default WebAuthnHandler;\n"],"names":["WebAuthnHandler","show","error","setError","useState","webAuthnError","handleLogin","event","autoFill","asseResp","options","axios","startAuthentication","verificationResponse","router","useEff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