Is there a way to determine if signout has success...
# support-questions-legacy
c
Is there a way to determine if signout has successfully executed on the frontend? I would like to redirect only upon successful signout, for example
It seems like null/undefined is returned. I did let res = await signOut() and nothing showed when I tried printing out res
n
Hi @chunkygoo.
What SDK are you using?
To clarify, I meant which frontend SDK are you using
c
"supertokens-auth-react": "^0.26.4",
n
You can use the onHandleEvent hook, refer to this part of the docs: https://supertokens.com/docs/thirdparty/advanced-customizations/frontend-hooks/handle-event
c
That specifies sign in and up, is there one for sign out?
c
Does that happen AFTER sign out? Or when sign out is clicked?
n
After sign out is done
c
Awesome thank you!
n
Happy to help
c
Seems like this doesn't work if I need hooks?
Copy code
await signOut();
    router.push('/home');
This is what I am trying to do
But I get redirected before logging out
const router = useRouter();
useRouter cannot be used in frontendConfig
n
Right, useRouter can only be used inside React components
c
Any workarounds?
n
Try
import Router from "next/router
and calling functions on that
c
But I also need other hooks
like useTranslation
n
You want to use useTranslation in the onHandleEvent hook?
c
Yes
n
Hmm
c
I want to use useTranslation in frontendConfig
As I want to notify the user when they log out
n
Ah right, one way I can think of doing it is to fire a window event from the onHandleEvent hook and then consuming that inside of your component where you can use the hooks
c
hmm seems unnecesarily complicted
Is there a way to wrap signout so that it returns a promise?
What's the rationale for signout to not return anything?
n
So just to make sure I understand correctly, you simply want to do something after sign out completes correct?
c
yes
but these actions require hookls
n
Can I see how you are importing sign out?
c
import { signOut } from 'supertokens-auth-react/recipe/emailpassword';
n
So that does return a Promise
Did you face any issues when awaiting it?
c
Copy code
let handleLogout = async () => {
    let res = await signOut();
    console.log(res);
    router.push('/home');
  };
res is undefined
n
Right it does not return a value but it throws if it fails
c
So does it return a promise or not?
n
It returns
Promise<void>
c
I see
n
Meaning the result is undefined
So simply awaiting it is what youre looking for
c
Interesting
my understanding is that
since I am awaiting signout()
router.push('/home'); will get executed after signout is done executing
right?
n
Yep that is correct
c
But sometimes
I am not sure why but maybe it's the context api updating too slowly
the component i render does not immediately change it's values
so right now i check for does session exist
if it does, render "logout"
else render "login/signup"
upon logout, the text should immediately change to "login/signup"
but that is not the case
n
hmm there could be a couple things going on here, like you said it could be that the context update is slow or it could be something else
I would need to see a more complete code snippet to help
We can start with how you are calling doesSessionExist
c
It only happens sometimes though
not sure why
Right now it's not happening anymore 🥲
n
Yeah its hard to pinpoint the issue without looking at more code, from what ive seen you are calling sign out correctly so unless you are seeing errors that is working correctly
c
Ok if I realize this again I will be back but could you take a look at the other thread