// Import the registration hookimport {useRegistration} from'webauthn-helper';// Create your register function.// By default the urls are "/register" and "/register/options"// but you can change those urls if needed.constregister=useRegistration({ actionUrl:'/api/register', optionsUrl:'/api/register/options'});// We can call this register function whenever we need (e.g. form submission)register({ username:'john.doe', displayName:'JD'}).then((response) =>console.log('Registration success')).catch((error) =>console.log('Registration failure'));
Additional options can be set during the registration process. See the section “Deep into the framework” to know more. Hereafter another example:
The specification Webauthn L2 deprecates the use of the parameter requireResidentKey; you should use residentKey instead with one of the following value: required, preferred or discouraged.
To have the same behavior as above, please use required.
Authentication
// Import the login hookimport {useLogin} from'webauthn-helper';// Create your login function.// By default the urls are "/login" and "/login/options"// but you can change those urls if needed.constlogin=useLogin({ actionUrl:'/api/login', optionsUrl:'/api/login/options'});// We can call this login function whenever we need (e.g. form submission)login({ username:'john.doe'}).then((response) =>console.log('Authentication success')).catch((error) =>console.log('Authentication failure'));
As done during the registration, additional options are available. See the section “Deep into the framework” to know more. Hereafter another example: