Hi, I am getting a blank screen in react if there is an error in the backend during authentication o...
l
Hi, I am getting a blank screen in react if there is an error in the backend during authentication or if the backend is down. Is there any way to do a redirect to an error page on error?
r
Hey! Is this for your own routes? Or the routes which are handled by the SDK?
Perhaps @porcellus can pitch in here
l
for the sdk routes and the routes wrapped into Thirdpartyemailpassword components
Copy code
<Route path={'*'} element={<ThirdPartyEmailPasswordAuth>
       <ProtectedZone/>
       </ThirdPartyEmailPasswordAuth>}
       />
r
Right. And have you enabled email verification feature?
l
no
r
Hmmm. So which api requests are failing in that case? From the network tab
l
its activated, sorry i've read failure instad of feature
r
Ah right. So I assume the api that checks if an email is verified fails?
l
all requests to my backend are failing because i turned if off
r
Does your frontend have an error boundary?
Also, are you running the app in production build of development build?
Or*
l
there is no error bounery. I am running in dev mode. But normally, if there is an error, an error screen is shown. But here, the page is blank
r
Agreed. So this might be a bug on our side
l
The same problem occures, ater deleting users which are currently logged in. If they refresh the page, it is blank. This can only be fixed by deleting the cookies but this is not a valid solution for end users
r
Hmmmm. Can you enable your backend, but just switch of the supertokens core. And then see what the behaviour is?
Cause here your backend APIs that don’t query the supertokens core will work. Just the supertokens APIs will fail.
l
i am using the hosted service. I can disable supertokens.init
r
Change the connection uri to some random domain
Or put an invalid api key
l
same result - blank page
r
Can we get on a quick debugging call?
l
Unfortunately, no
r
hmm. Okay. Then i'll try and reproduce the issue myself
one more questions - does this happen if you are logged in & logged out? Or just one of the two states?
l
The error message with a wrong api key is like expected:
Copy code
supertokens_python.exceptions.GeneralError: SuperTokens core threw an error for a GET request to path: /apiversion with status code: 401 and message: Invalid API key
r
right.
l
only if i am logged in
r
got it. Thanks.
l
respectively if supertokens cookies are set
r
cool
we will release a fix for this sometime today / tomorrow. If you want is now, you can do
Copy code
npm i git+https://github.com:supertokens/supertokens-auth-react.git#next-breaking-change
And then see if the issue still happens.
l
Thanks, i will try it out in 1-2h
@rp_st i am still getting a blank page
r
Hmm. Are you sure you are using the right version? Did a rebuild? Cleared cache?
l
from ackage.json:
Copy code
"supertokens-auth-react": "github:supertokens/supertokens-auth-react#next-breaking-change",
I restarted the dev server
r
Can you delete node modules, package-lock.json and reinstall?
l
yes. It will take some time. My internet connection is very slow
r
Cool
p
also, can you check the console logs please?
l
@rp_st still a blank page
@porcellus the console is empty
r
Which api call is failing from the network tab?
l
/auth/user/email/verify
r
Hmm. I ran the exact same scenario, and for me it shows the error stack
l
My root container is empty . should that be?
p
Yeah, if an error is thrown like this it unmounts the entire react tree.
l
Ok. But i cant see an error.
p
that's strange. if you refresh with the console open nothing gets logged?
l
But if a do something like console.log(undefined.test) i am getting an error
console is still empty
p
do you have an error boundary around it your app? that might be catching the error.
r
No error boundary
Mentioned above
p
oh, sorry, didn't see.
r
@Luca would it be possible to upload some part of your code on GitHub so that we can replicate this?
Cause the error stack is showing for us on the version of that branch
l
After reinstallig my dependencies all errors are not resulting in an error page
r
Not or now?
l
not - page is blank
r
Would it be possible to get on a call at all to help fix this?
Tomorrow or day after
l
@rp_st M Internet connection is slow last days - zoom is loosing connection all 2 minutes or so. But i fixed the issue and now i am getting
TypeError: Failed to fetch
It this like expected?
r
that happens when the backend is not running and you query it. So yea.. it's expected
l
ok, this wasn't shown before
How can i install the version with the fix? seams like the next-breaking-change branch is no longer available
r
oh yea.
Copy code
npm i git+https://github.com:supertokens/supertokens-auth-react.git#0.25
l
i am getting still a blank page if i provide an invalid api key. What works is something like in my global fetch override:
Copy code
javascript
const res = await origFetch(input, init)
const url = input.url || input
if (isApiDomain(url)) {
    ...
    if (url.includes('/auth') && res.status === 500) {
        throw new Error('Suppertokens error')
    }
}
r
hmmm
would it be possible for your to upload your code so that we can replicate it?
l
Yey. I will extract the relavant parts and upload it to gitup
r
perfect! thanks
you can invite me to the project
my github is rishabhpoddar
l
I added you to my frontend repo. You need to use the dev branch
r
ok thanks
So i tried your app, it turns out that if you wrap your app with an error boundary, the error boundary UI does show up
So it's react being selective in showing the stack vs not
but the error is indeed getting propagated correctly.
l
@rp_st could you show me what you've changed plase?
r
I just created an error boundary component like this:
Copy code
ts
class ErrorBoundary extends React.Component<unknown, ErrorBoundaryState> {
    constructor(props: { hasError: boolean }) {
        super(props);
        this.state = { hasError: false };
    }

    static getDerivedStateFromError(): ErrorBoundaryState {
        return { hasError: true };
    }

    componentDidCatch(error: Error, errorInfo: ErrorInfo): void {
        console.info(error, errorInfo);
    }

    render(): JSX.Element | ReactNode | undefined {
        if (this.state.hasError) {
            return "Error boundry UI";
        }

        return this.props.children;
    }
}
And wrapped the whole app with this component.
this is thanks to @porcellus
l
Ok, this works. But i am wondering why react is not showing the error overlay by default
r
no idea
should ask react folks
l
The problem now with the error boundary is, that is catches all errors. But i want to do something if an error occurres during supertokens auth
would be good if there would be something like an onError callback
Or I need to wrap my ProtectedZone inside another error boundary
p
well this only catches error that'd otherwise crash your entire app
you can be selective inside
componentDidCatch
and rethrow them if you can't handle the error in a meaningful way (but you'd end up with a white screen anyway)
l
@rp_st @porcellus thanks for all your help. Now I have a status page if my Backend is not reachable and automatic logout in case of there are stored cookies for an user which does not exist anymore - exactly what i need.
5 Views