Passkey
WebAuthn in MoonSDK
React WebAuthn Component
import React, { useState } from 'react';
import { startAuthentication, startRegistration } from '@simplewebauthn/browser';
import { MoonSDK } from '@moonup/moon-sdk';
const sdk = new MoonSDK();
function WebAuthnComponent() {
const [email, setEmail] = useState('');
const handleLogin = async () => {
const auth = await sdk.handlePassKeyLogin(email);
const credential = await startAuthentication(auth);
const response = await sdk.handlePasskeyLoginVerify(email, credential);
};
const handleRegister = async () => {
const options = await sdk.handleRegister(email);
const credential = await startRegistration(options);
const token = await sdk.handleRegisterVerify(email, credential, options);
};
return (
<div>
<input type="email" onChange={(e) => setEmail(e.target.value)} />
<button onClick={handleLogin}>Login with WebAuthn</button>
<button onClick={handleRegister}>Register with WebAuthn</button>
</div>
);
}
export default WebAuthnComponent;WebAuthn in MoonSDK
Benefits of WebAuthn in MoonSDK
Conclusion
Last updated