EOSCommunity.org Forums

Logout, removeSession in Anchor Link?

Hi, I hope this is the right spot for technical questions.

Could you show a quick example of how to logout the user?
link.removeSessions doesn’t seem to work, when I print the session list after removeSession (seesions2) I still see the session there.

Absolutely, it’s the best place to answer questions like this :wink:

I think you have it correct in terms of parameters (appname, auth, chainid), but the removeSession call is async, so you’ll want to await that:

await link.removeSession('eospowerupio', sessions[0].auth, sessions[0].chainId)

I think what’s happening in the above code is the listSessions call for sessions2 is executing before the removal of the session takes place.

If you’re trying to logout all accounts and want a quicker path, you can also use the clearSessions call to log out any and all accounts without having to do as many checks:

await link.clearSessions('eospowerupio')

That’ll clear out any sessions within the adapter. I don’t know if you’re aiming for this to be a single user logout or logout all users, but it’s an option!

Ok great, yes I guess I missed that I need to await the removeSession, and good to know about clearSessions as well :+1:

1 Like