Skip to content

Instantly share code, notes, and snippets.

@IanMitchell
Created March 13, 2024 16:31
Show Gist options
  • Save IanMitchell/3d66f5366e2765c2f59beea9732a117a to your computer and use it in GitHub Desktop.
Save IanMitchell/3d66f5366e2765c2f59beea9732a117a to your computer and use it in GitHub Desktop.
Code Syntax Example
+import { Fragment, useEffect, useState } from "react";
+import { supported } from "@github/webauthn-json";


export default function Register() {
  const [username, setUsername] = useState("");
  const [email, setEmail] = useState("");
+  const [isAvailable, setIsAvailable] = useState<boolean | null>(null);


+  useEffect(() => {
+    const checkAvailability = async () => {
+      const available =
+        await PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable();
+      setIsAvailable(available && supported());
+    };
+
+    checkAvailability();
+  }, []);


  return (
    <Fragment>
      <h1>Register Account</h1>
+      {isAvailable ? (
        <form method="POST" onSubmit={onSubmit}>
          // Form Here - snipping it for length
        </form>
+      ) : (
+        <p>Sorry, WebAuthn is not available.</p>
+      )}
    </Fragment>
  );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment