Best practice for handling logout / passport switch with DID Connect
Hi ArcBlock team,
I’m building a custom React app using DID Connect for authentication.
I’m trying to achieve a clean, deterministic behavior where logging out or switching passports results in a full identity reset, so the app behaves as if it were freshly loaded for the new user (both client and server side).
From a best-practice standpoint:
- What is the recommended way to handle logout / passport switching with DID Connect?
- Is
session.logout()expected to fully invalidate the session, or is there an additional step required on the app/server side? - How should an app reliably detect that the active identity has changed and react accordingly?
I want to make sure I’m aligning with the intended usage patterns rather than working against the framework.
Thanks.
Mario
4 条回复
Hi Mario,
You can use
useEffectto monitor changes insession.userOr just use event subscription
🙏🏼
I'm able to detect the lost of auth, but my app is still requiring a hard refresh in order to pick up the changes. This causes the app to be in a stale state. I noticed on my pages kit app for instance, if I logout and am on a page which requires auth, my page immediately flips. Any suggestions on how to trigger that and avoid the stale state?
I think what you need is here: https://docsmith.aigne.io/docs/did-connect-react/en/core-components-session-provider-557476#basic-setup