hi! how can i prevent `SignInUp` component from ...
# support-questions-legacy
y
hi! how can i prevent
SignInUp
component from
supertokens-auth-react/recipe/passwordless
redirecting to
/auth
i am overriding it to only confirm
OTP
by creating
verify-phone
route, and adding this to frontend config
signInUpFeature: { disableDefaultUI: true }
i did this by following phone + password guide
r
Hey!
SignInUp
from passwordless will redirect to /auth if a session does not exist already. You want to use that as a second factor correct?
y
r
right, and have you overridden the doesSessionExist function to check for
forceOriginalCheck
from the userContext?
y
yep
let me say this
it was working fine, until i started working on it again and it broke somehow
i even rolled back my git commits
and even then it didn't work
i have no idea what's going on
r
whats the behaviour that you are seeing now?
can you upload your code on github and share it with me? Otherwise it's really difficult to know
y
after register -> redirect /auth/verify-phone -> redirect /auth -> loop again
r
can I see your doesSessionExist override?
y
Copy code
js
 SessionReact.init({
        override: {
          functions: oI => {
            return {
              ...oI,
              doesSessionExist: async function (input) {
                let sessionExists = await oI.doesSessionExist(input)
                if (!sessionExists) {
                  // none of the login challenges are complete. So we do not give access
                  return false
                }

                if (input.userContext.forceOriginalCheck === true) {
                  return true
                }

                if (window.location.pathname.startsWith('/auth')) {
                  if (window.location.pathname === '/auth/verify-phone') {
                    // this is a special case route where even if a session exists,
                    // we say it doesn't exist unless the second login challenge is solved
                    let accessTokenPayload =
                      await SessionReact.getAccessTokenPayloadSecurely()
                    return accessTokenPayload.phoneNumberVerified === true
                  }
                  return true
                } else {
                  // these are routes on which the user's app pages exist. So we must allow
                  // access to them only when they also have their phone number verified
                  let accessTokenPayload =
                    await SessionReact.getAccessTokenPayloadSecurely()
                  return accessTokenPayload.phoneNumberVerified === true
                }
              },
            }
          },
        },
      }),
r
y
same redirect loop
r
are you sure you are building / clearing cache etc?
y
give me a sec 🙂
r
and can you print out some logs in your doesSessionExist override and see what is getting printed out when you visit the second factor page?
y
i am using nextjs btw, so i wrap SignUpIn as dynamic component with ssr disabled, and also i do
rm -rf .next/ && yarn dev
so that cache is not a factor
r
ok
y
yes, it registers
maybe the check can't finish because redirect is too fast?
i don't even know haha
so you thing that doesSessionExist is the problem? that's what i think too
r
What are the logs that are being printed out?
y
i checked on other page, it prints the context, which is the first argument but i can't really check it on auth pages, because they keep redirecting
oh it does print on /auth/verify-phone page
i did
console.log(input)
on top of
doesSessionExist
override
r
can you add logs to each part of the override function and see what is getting executed? You can enable persist logs in chrome to keep the logs across redirects. If you still can't figure it out, please upload your code on github, so that I can have a look that way. It's really hard to help out without seeing the code
you may also want to try just running our demo app as it is and seeing if that works.. then you can step through how your implementation is different to debug
y
hmmmmmmmmm, actually in verify phone page the context should have been
{ forceOriginalCheck: true }
, but it is empty object
r
right yea.. so thats the issue
check your useEffect code. If that seems fine, you can open an issue about it on our github
y
SuperTokensWrapper wraps the
_app.tsx
is that okay?
r
oh right.. that is OK
one sec.
right.. i think i may know what the problem is. Let me check it out and update the demo app. Will get back to you
y
context actually is there, i think the object appeared to be empty because of chrome object storing by reference, so i stringified the context
r
right.
Give me sometime.
There might be an issue with the demo app code.
y
ok, thank you
r
Fixed the demo app -> https://github.com/supertokens/supertokens-auth-react/blob/master/examples/with-phone-password/src/App.tsx#L174 We needed to add a
key
prop to
SuperTokensWrapper
which makes it recalculate the session context on path change. This is needed cause the
doesSessionExist
override reads from the window path
y
wow, thanks man!
you are great!
r
cool! lmk if this works
thanks for pointing out this issue
y
it does work
r
ok nice
y
umm, can i ask more questions? 🙂
when i try to navigate to
/auth?lang=somelang
, it redirects to
/auth
without query params
r
so while you are on /auth, it redirects to /auth again? How are you redirecting?
y
whoops, my bad, it's my code
sorry 😅
r
cool