Last active
March 13, 2024 16:44
-
-
Save IanMitchell/427f89c45019750bd5a31101d40c975c to your computer and use it in GitHub Desktop.
Code Syntax Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```tsx title="pages/register.tsx" | |
import { Fragment, useEffect, useState } from "react"; // [!code ++] | |
import { supported } from "@github/webauthn-json"; // [!code ++] | |
export default function Register() { | |
const [username, setUsername] = useState(""); | |
const [email, setEmail] = useState(""); | |
const [isAvailable, setIsAvailable] = useState<boolean | null>(null); // [!code ++] | |
useEffect(() => { // [!code ++] | |
const checkAvailability = async () => { // [!code ++] | |
const available = // [!code ++] | |
await PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable(); // [!code ++] | |
setIsAvailable(available && supported()); // [!code ++] | |
}; // [!code ++] | |
// [!code ++] | |
checkAvailability(); // [!code ++] | |
}, []); // [!code ++] | |
return ( | |
<Fragment> | |
<h1>Register Account</h1> | |
{isAvailable ? ( // [!code ++] | |
<form method="POST" onSubmit={onSubmit}> | |
// Form Here - snipping it for length | |
</form> | |
) : ( // [!code ++] | |
<p>Sorry, WebAuthn is not available.</p> // [!code ++] | |
)} // [!code ++] | |
</Fragment> | |
); | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment