ceramicstudio / self.id

Developer suite for decentralized user identity
https://self.id
Other
99 stars 32 forks source link

useViewerConnection hook doesn't re-connect after refresh #81

Closed bcowell closed 2 years ago

bcowell commented 2 years ago

Description

Connecting a wallet using the useViewerConnection hook and a Provider. Refreshing the page, the connection of useViewerConnection never tries to re-connect.

Isn't this hook supposed to handle this connection lifecycle? My metamask wallet continues to say it's connected. And the useViewerID hook still properly pulls my id after refresh.

Result:

  1. Connect my metamask wallet using useViewerConnection.connect a. This works and connection status returns { status: 'connected', selfID: SelfID }. Cookies, etc. are set.
  2. Refresh the page a. useViewerConnection.connection is { status: 'idle' }

Expected:

  1. Connect my metamask wallet using useViewerConnection.connect a. This works and connection status returns {status: 'connected', selfID: SelfID}. Cookies, etc. are set.
  2. Refresh the page a. useViewerConnection.connection returns {status: 'connected', selfID: SelfID}

Technical Information

Version @self.id/framework: ^0.3.2 Re-calling connect puts some info into localStorage under 3idconnect.org - this is wiped on refresh

Example

import { useViewerID, useViewerConnection } from "@self.id/framework";

const MyComponent = () => {
  const [connection, connect, disconnect] = useViewerConnection();
  const viewerID = useViewerID();

  console.log(viewerID?.id);
  console.log(connection);

return ...
}
bcowell commented 2 years ago

Also the status should likely be 'disconnected' after firing the cleanup versus 'idle' to differentiate the two

PaulLeCam commented 2 years ago

If you refresh the page, the JS state is reset, so it's the expected behavior. The viewer ID is persisted by cookie so it can be used for read-only access, but any authentication state is lost on page refresh.