I’m trying to authenticate user using passkey, at the VerifyAuthenticateResponse method, I faced an issue of no getting logged in, instead the server thrown this kind of error which I didn’t exepected. Firstly I thought, the data is stored in mongodb so let’s convert back to normal js format then too it didn’t work. The attribute passkey stored in mongodb is of type Mixed.
exports.loginVerification = async (req, res) => {
try {
const { username, credential } = req.body;
if (!username || !credential) {
return res.status(400).json({
status: "fail",
message: "Username and credential are required",
});
}
const user = await User.findOne({ username }).select("-password");
if (!user) {
return res.status(404).json({
status: "fail",
message: "User not found",
});
}
const challenge = await Challenge.findOne({ userId: user._id });
if (!challenge) {
return res.status(404).json({
status: "fail",
message: "Challenge not found",
});
}
const userObject = user.toObject();
const credentialId = userObject.passkey.credentialID;
const credentialPublicKey = userObject.passkey.credentialPublicKey;
const counter = userObject.passkey.counter;
console.log({
passkey: userObject.passkey,
});
const result = await verifyAuthenticationResponse({
expectedOrigin: process.env.ORIGIN,
expectedRPID: process.env.RP_ID,
response: credential,
expectedChallenge: challenge.challenge,
authenticator: userObject.passkey,
});
console.log({ result });
if (!result.verified) {
return res.status(401).json({
status: "fail",
message: "Verification failed",
});
}
res.status(200).json({
status: "success",
verified: result.verified,
message: "Verification successful",
user,
});
} catch (error) {
console.log(error);
res.status(400).json({
status: "fail",
message: error.message,
});
}
};
Getting an error as –
Error: No data
at Object.decodePartialCBOR (D:fullstackpasskey-authenticationservernode_modules@levischucktiny-cborscriptcborcbor.js:355:15)
at Object.decodeFirst (D:fullstackpasskey-authenticationservernode_modules@simplewebauthnserverscripthelpersisoisoCBOR.js:25:40)
at decodeCredentialPublicKey (D:fullstackpasskey-authenticationservernode_modules@simplewebauthnserverscripthelpersdecodeCredentialPublicKey.js:6:84)
at verifySignature (D:fullstackpasskey-authenticationservernode_modules@simplewebauthnserverscripthelpersverifySignature.js:20:86)
at verifyAuthenticationResponse (D:fullstackpasskey-authenticationservernode_modules@simplewebauthnserverscriptauthenticationverifyAuthenticationResponse.js:157:66)
at async exports.loginVerification (D:fullstackpasskey-authenticationservercontrollerschallenge.controller.js:182:20)
Response ouput
I was trying to finally authenticate the user but this issue came and I’m storing the data on mongodb.