Hi all, Is there a way to create a test user who c...
# support-questions-legacy
v
Hi all, Is there a way to create a test user who can login without otp
r
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
yeah
r
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
supertokens-react-native
r
backend?
and are you using the passwordless recipe or something else?
v
yeah
r
which backend sdk?
node?
v
node sdk
yeah
r
try something like this on the backend:
Copy code
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
Ok
Will check and let you know
made this change in backend
Do i have make any change in front end
r
No frontend change needed
v
ok
failing after the change
r
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
ok
Thanks you @rp_st Working now
m
@rp_st 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
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
Copy code
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
You need to call the original implementation to send the sms…
m
The other override is service level override, which is used for OTP customisation
r
I think Iv been clear enough and have already helped out a lot. Hope you can figure it out 🙂
m
sure thing.. you have been very helpful
10 Views