async registerUser(username: string, name: string) {
this.getMakeCredentialsChallenge({username, name}) //Client sends the user’s data to the server - Ends step 1
.then(response => { //Begins step 3
let publicKey;
if (response.success) {
//The Client decrypts the challenge and user ID generating an object
publicKey = this.preformatMakeCredReq({
status: response.status,
challenge: response.challenge,
rp: response.rp,
user: response.user,
attestation: response.attestation,
pubKeyCredParams: response.pubKeyCredParams,
});
}
return (navigator as any).credentials.create({publicKey}); //Here the browser asks the user to use a valid authenticator - Ends step 3
})
.then(response => { //Begins step 5
const makeCredResponse = this.publicKeyCredentialToJSON(response); //Generates the object to respond with the result of the interaction between the user and the authenticator
return this.sendWebAuthnResponse(makeCredResponse); //It is sent to the server
}) //Ends step 5
.then(response => { //The server verifies that everything is ok
if ((response as any).rawResponse.data.status === "ok") {
this.loadMainContainerRegister();
} else {
alert(`Server responed with error. The message is: ${(response as any).rawResponse.data.message}`);
}
})
.catch(error => alert(error));
}