SMS based authentication issue AppwriteException: Missing required parameter: "secret"
- 0
- React Native
- Auth
Hi, I am creating sms based login. I am able to send SMS code to my real number however I am receving this error. I can log the "secret" and i can see it is not missing but appwrite is complaining for it. Here is my code.
// 1) Send OTP (creates user automatically if phone is new)
const result= await account.createPhoneToken( ID.unique(), phone);
console.log("SMS based login userid:", result.userId);
return result;
}
async function verifySMS(userId, code) {
// Completes the phone login with the OTP
const secret = String(code).trim();
console.log("SMS secret:", secret);
if (!secret) throw new Error('Code is empty');
// Preferred method for phone OTP:
if (typeof account.updatePhoneSession === 'function') {
await account.updatePhoneSession({ userId, secret });
} else if (typeof account.createSession === 'function') {
// Fallback for older SDKs that still accept token session here
await account.createSession({ userId, secret });
} else {
throw new Error('No suitable session method found in this SDK build');
}
}```
My console log is able to print the "secret" but still getting the error. Here is the console log.
``` LOG SMS based login userid: 68b9efa2001babcdc63
LOG SMS secret: 254643
WARN [AppwriteException: Missing required parameter: "secret"]``` I tried with the Mock number and real number.
As you can see in the logs. The verifySMS() function is receiving userId and code and then it is injecting these required parameters into account.updatePhoneSession() method. Not sure why it is still complaining about " Missing required parameter: "secrete""
Issue is resolved. Thanks here is the correct version of code, in case someone needs it. ``` async function loginSMS(phone) {
const result= await account.createPhoneToken( ID.unique(), phone);
return result;
}
async function verifySMS(userId, code) {
const secret = String(code).trim();
if (!secret) throw new Error('Code is empty');
if (typeof account.updatePhoneSession === 'function') { await account.updatePhoneSession( userId, secret ); } else if (typeof account.createSession === 'function') {
await account.createSession( userId, secret );
} else {
throw new Error('No suitable session method found in this SDK build');
}
}```
Recommended threads
- Redirect from clicking team invite link ...
Hi all! Pretty new to app development in general so this might be something more generic than appwrite, but I've found (after reading the docs for the Teams API...
- Email address must be in its canonical f...
Hello, Recently I was trying to signup with my GitHub account with appwrite account for availing the student benifits but while trying to signup I saw such erro...
- help!!!!
whats happening no clue pls help 🥲