Skip to content

Instantly share code, notes, and snippets.

@IanMitchell
Last active March 13, 2024 16:44
Show Gist options
  • Save IanMitchell/427f89c45019750bd5a31101d40c975c to your computer and use it in GitHub Desktop.
Save IanMitchell/427f89c45019750bd5a31101d40c975c to your computer and use it in GitHub Desktop.
Code Syntax Example
```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