跳到主要内容
ArcBlock Community

Best practice for handling logout / passport switch with DID Connect

Twelve
开发者
blocklet-serverdiscussionresolved

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 条回复

zhanghan7个月前

Hi Mario,

You can use useEffect to monitor changes in session.user

javascriptCopy
const { session } = useSessionContext();
useEffect(() => {
  if (session?.user) {
    console.log('user logged in');
  } else {
    console.log('user logged out');
  }
}, [session.user]);

Or just use event subscription

Twelve7个月前

🙏🏼

Twelve7个月前

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?

回复