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
- Bug report: Race condition in Flutter SD...
Hi team, I've found an intermittent bug in the Flutter SDK (v20.3.0) when using `createOAuth2Session` on Android. **Symptoms** After `createOAuth2Session` re...
- DB Relational Table Request
Hi, I'd like to suggest a rewording of the relationships between tables. - Current wording: storeOperatingDays can contain one storeId ...
- Domain is already used. Please try again...
I have a website with where the www.domain.me This website works just fine But if I try to visit domain.me. I get this error. I keep getting sent to some app ri...