https://supertokens.com/ logo
Title
c

Chunkygoo

10/04/2022, 5:00 AM
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

nkshah2

10/04/2022, 5:09 AM
Hi @Chunkygoo
What SDK are you using?
To clarify, I meant which frontend SDK are you using
c

Chunkygoo

10/04/2022, 5:10 AM
"supertokens-auth-react": "^0.26.4",
n

nkshah2

10/04/2022, 5:14 AM
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

Chunkygoo

10/04/2022, 5:15 AM
That specifies sign in and up, is there one for sign out?
c

Chunkygoo

10/04/2022, 5:17 AM
Does that happen AFTER sign out? Or when sign out is clicked?
n

nkshah2

10/04/2022, 5:17 AM
After sign out is done
c

Chunkygoo

10/04/2022, 5:17 AM
Awesome thank you!
n

nkshah2

10/04/2022, 5:17 AM
Happy to help
c

Chunkygoo

10/04/2022, 5:51 AM
Seems like this doesn't work if I need hooks?
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

nkshah2

10/04/2022, 5:53 AM
Right, useRouter can only be used inside React components
c

Chunkygoo

10/04/2022, 5:53 AM
Any workarounds?
n

nkshah2

10/04/2022, 5:54 AM
Try
import Router from "next/router
and calling functions on that
c

Chunkygoo

10/04/2022, 5:54 AM
But I also need other hooks
like useTranslation
n

nkshah2

10/04/2022, 5:55 AM
You want to use useTranslation in the onHandleEvent hook?
c

Chunkygoo

10/04/2022, 5:55 AM
Yes
n

nkshah2

10/04/2022, 5:55 AM
Hmm
c

Chunkygoo

10/04/2022, 5:55 AM
I want to use useTranslation in frontendConfig
As I want to notify the user when they log out
n

nkshah2

10/04/2022, 5:56 AM
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

Chunkygoo

10/04/2022, 5:59 AM
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

nkshah2

10/04/2022, 6:02 AM
So just to make sure I understand correctly, you simply want to do something after sign out completes correct?
c

Chunkygoo

10/04/2022, 6:02 AM
yes
but these actions require hookls
n

nkshah2

10/04/2022, 6:02 AM
Can I see how you are importing sign out?
c

Chunkygoo

10/04/2022, 6:02 AM
import { signOut } from 'supertokens-auth-react/recipe/emailpassword';
n

nkshah2

10/04/2022, 6:03 AM
So that does return a Promise
Did you face any issues when awaiting it?
c

Chunkygoo

10/04/2022, 6:04 AM
let handleLogout = async () => {
    let res = await signOut();
    console.log(res);
    router.push('/home');
  };
res is undefined
n

nkshah2

10/04/2022, 6:05 AM
Right it does not return a value but it throws if it fails
c

Chunkygoo

10/04/2022, 6:05 AM
So does it return a promise or not?
n

nkshah2

10/04/2022, 6:05 AM
It returns
Promise<void>
c

Chunkygoo

10/04/2022, 6:05 AM
I see
n

nkshah2

10/04/2022, 6:05 AM
Meaning the result is undefined
So simply awaiting it is what youre looking for
c

Chunkygoo

10/04/2022, 6:05 AM
Interesting
my understanding is that
since I am awaiting signout()
router.push('/home'); will get executed after signout is done executing
right?
n

nkshah2

10/04/2022, 6:06 AM
Yep that is correct
c

Chunkygoo

10/04/2022, 6:06 AM
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

nkshah2

10/04/2022, 6:09 AM
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

Chunkygoo

10/04/2022, 6:10 AM
It only happens sometimes though
not sure why
Right now it's not happening anymore 🥲
n

nkshah2

10/04/2022, 6:11 AM
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

Chunkygoo

10/04/2022, 6:11 AM
Ok if I realize this again I will be back but could you take a look at the other thread