Greenruhm / connect

Greenruhm Connect is your white label, custom-branded connection to the music metaverse. It allows you to provide music NFT services inside your app with your branding.
MIT License
1 stars 0 forks source link

Keep clients updated about users sign in status #79

Open brunomoutinho opened 1 year ago

brunomoutinho commented 1 year ago

When a client initializes a connect client, they should have some way to know about a user's sign in status updates.

Proposed solution:

  1. Implement middlewares in connect store;
  2. Create a middleware that listens to the sign in status changes;
  3. Call up a passed-in function to inform client about status changes.

API Usage:

connect({ key, onSignedIn, onSignedOut }) => ({ signUp(), signIn(), signOut(), selectUser(), isUserSignedIn(), ...otherProps })
brunomoutinho commented 1 year ago

@ericelliott I am facing a problem and would like your feedback.

Currently, the connect SDK is being instanced in whatever component that wants to use them.

Ideally, we should not have many instances of the SDK at the same time, I believe, since we have the store being created and managed inside of the SDK.

From there, I was thinking about how to instantiate the SDK and thought it would be nice to have a Provider/Hook pattern to access the SDK. So I created them, the SDK is instantiated when the Provider is created. This sounds great, but this makes it not feasible to use the SDK in Redux Sagas, for example, because you cannot access the Provider state from outside of the component tree.

This made me think that we could use a Singleton pattern. This makes the Provider/Hook pattern unnecessary if I expose a method that gets the Singleton SDK instance (which could be something like useConnect, which resembles the hook pattern), and can also be used in the Redux Sagas.

How do you feel about this solution? Is there any other pattern I should explore?