https://supertokens.com/ logo
Title
v

vikram_shadow

01/24/2023, 5:12 AM
Hi all, Is there a way to create a test user who can login without otp
r

rp

01/24/2023, 5:13 AM
hey @vikram_shadow There are different ways of doing this, but the easiest way is to console log the otp on the backend by overriding the sendSms function in the smsDelivery config - in case it's a test user.
hey @vikram_shadow let's talk on this thread
So i assume that you will tell the tester which phone number to use correct?
v

vikram_shadow

01/24/2023, 6:18 AM
yeah
r

rp

01/24/2023, 6:18 AM
in this case, you could override the consumeCode function on the backend to: - detect that the input phone number is of the tester. You can get the phone number by using the preAuthSessionId from the function input and querying the passwordless recipe to get the device info used for login (which contains the phone number used) - If that phone number is used, do not call original impelmentation, instead, call passwordless.signinup function instead (https://supertokens.com/docs/nodejs/modules/recipe_passwordless.html#signInUp) - return the response from the above function call. In this way, you are affectively allowing the tester to use any OTP and it will log them in
if you tell me which SDK, i can share some code snippets
v

vikram_shadow

01/24/2023, 6:19 AM
supertokens-react-native
r

rp

01/24/2023, 6:20 AM
backend?
and are you using the passwordless recipe or something else?
v

vikram_shadow

01/24/2023, 6:20 AM
yeah
r

rp

01/24/2023, 6:20 AM
which backend sdk?
node?
v

vikram_shadow

01/24/2023, 6:21 AM
node sdk
yeah
r

rp

01/24/2023, 6:24 AM
try something like this on the backend:
ts
Passwordless.init({
    contactMethod: "...",
    flowType: "...",
    override: {
        functions: (original) => {
            return {
                ...original,
                consumeCode: async function (input) {
                    let device = await Passwordless.listCodesByPreAuthSessionId({
                        preAuthSessionId: input.preAuthSessionId
                    });
                    if (device !== undefined) {
                        if (device.phoneNumber === "TEST_PHONE_NUMBER") {
                            let user = await Passwordless.signInUp({
                                phoneNumber: "TEST_PHONE_NUMBER"
                            });
                            return {
                                status: "OK",
                                createdNewUser: user.createdNewUser,
                                user: user.user
                            };
                        }
                    }
                    return original.consumeCode(input);
                }
            }
        }
    }
})
v

vikram_shadow

01/24/2023, 6:28 AM
Ok
Will check and let you know
made this change in backend
Do i have make any change in front end
r

rp

01/24/2023, 6:46 AM
No frontend change needed
v

vikram_shadow

01/24/2023, 6:47 AM
ok
failing after the change
r

rp

01/24/2023, 7:05 AM
What’s the error?
Oh right yea. Sorry. I see the problem. It’s gonna go into an infinite loop
i have updated the code snippet above. Try that
v

vikram_shadow

01/24/2023, 7:12 AM
ok
Thanks you @rp Working now
m

mib200

01/24/2023, 5:13 PM
@rp but the above example, sends SMS
can't we whitelist a phone number and then use a hardcoded OTP
this will be very useful for Apple reviewsa
r

rp

01/24/2023, 5:14 PM
Yes it does. If you want to disable that, override the sendSms function and don’t call the original implementation if the phone number is the test one
Hardcoding the OTP will require more customisations. Not worth it.
m

mib200

01/24/2023, 5:15 PM
override: (oI) => {
            return {
              ...oI,
              sendSms: async function (input) {
                console.log('======= sendSms =============');
                // console.log('====================');
                // return input;
                // input
                console.log(input);
              },
            };
          },
I use this, but then it doesn't send the SMS at all
r

rp

01/24/2023, 5:15 PM
You need to call the original implementation to send the sms…
m

mib200

01/24/2023, 5:15 PM
The other override is service level override, which is used for OTP customisation
r

rp

01/24/2023, 5:16 PM
I think Iv been clear enough and have already helped out a lot. Hope you can figure it out 🙂
m

mib200

01/24/2023, 5:17 PM
sure thing.. you have been very helpful