I’m attempting to make a logout button and am trying to use the authClient.logout() method except I don’t know what arguments it takes (if any) and how i should structure the argument I’m coding in javascript. A simple example would be great!
It doesn’t take any arguments, an example from Kyle is here:
Edit: Actually you can optionally pass it a url to forward on to after logging out, see docs:
https://erxue-5aaaa-aaaab-qaagq-cai.raw.ic0.app/auth-client/classes/authclient.html#logout
Eg
await authclient.logout({returnTo:”https://xkcd.com/710/”})
Dear @anon74414410, should I recreate AuthClient after every await authclient.logout() call?
Thing is that "key" in set in init() method of AuthClient. This leads to this situation:
- Fresh page load
- Initialize AuthClient - inside its
init()method"key"variable is set (does not matter fromKEY_STORAGE_KEYor orEd25519KeyIdentity.generate()) - logout by calling
await authClient.logout()- at this moment storage is destroyed - without refreshing a page - login again. At
authorize-client-successphase onlyKEY_STORAGE_DELEGATIONkey is set to storage. - We are logged in but we have no
KEY_STORAGE_KEYin storage. - Refresh the page - we are NOT logged in, because we have no
KEY_STORAGE_KEYin storage
Which is better?
- set
KEY_STORAGE_KEYin the sameauthorize-client-successphase next toKEY_STORAGE_DELEGATION? - recreate AuthClient?
For what it’s worth, in Papyrs, I explicitely set authClient to undefined after logout to recreat it. I added following comment in my code about it for my future self:
Reset local object otherwise next sign in (sign in - sign out - sign in) might not work out - i.e. agent-js might not recreate the delegation or identity if not resetted
In NNS dapp we do not reset authClient explicitely because after each logout we reload the window anyway, therefore a new client will implicitely be loaded afterwards.
Two distinct solution but in both, a new instance of authClient is created.
Thanks for sharing your experience.
In all our products Usergeek/Canistergeek/Configeek I will also create a new AuthClient on logout ![]()
The goal of logout is to close all timeouts and reset all the values, but there is no harm in simply discarding the instance and starting over when you start a new session