Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More consistent behavior with holochain client: make signUp() return the AppAgentClient #102

Open
mattyg opened this issue Jul 27, 2023 · 4 comments

Comments

@mattyg
Copy link
Contributor

mattyg commented Jul 27, 2023

I'm not sure if this makes sense or is possible, but I think this would be a clearer api that is more consistent with AppAgentClient:

const holoClient: HoloEnvoyClient = await WebSdkApi.connect({...});
const client: AppAgentClient = await holoClient.signUp({});

The idea is the HoloEnvoyClient has all the functionality specific to Holo, while the AppAgentClient can be exactly the same interface as working with holochain. The signUp() function returns the actual client only after I have completed authentication.

It doesn't make sense to me that I should have access to the AppAgentClient before authenticating, and it requires more difference in code to setup a holo vs holochain connection in my app.

Let me know what you think or if this makes any sense @robbiecarlton

@robbiecarlton
Copy link
Contributor

Hey @mattyg - this surfaces a difference between the holo model and the holochain model.
In holochain there's no native concept of an "anonymous agent". If you install a happ and provide whatever membrane proof, you're in the membrane and have whatever read/write access the happ gives you.

In holo, this is equivalent to the agent that you have access to after you've completed the sign up form. (ie, called client.signUp).

But before you have called signUp, you have access to an instance of AppAgentClient that's a special anonymous agent. This agent doesn't have a source chain but still has access to the dht. It's useful for eg: allowing users to go to a holo hosted app and be able to browse a directory, or otherwise passively look at content without requiring them to immediately create an agent.

So as soon as await WebSdkApi.connect returns, you have an AppAgentClient

@mattyg
Copy link
Contributor Author

mattyg commented Aug 11, 2023

But before you have called signUp, you have access to an instance of AppAgentClient that's a special anonymous agent. This agent doesn't have a source chain but still has access to the dht. It's useful for eg: allowing users to go to a holo hosted app and be able to browse a directory, or otherwise passively look at content without requiring them to immediately create an agent.

Ok right, I thought I remembered something about anonymous agents.

So in that case, I wonder if .connect() should be connectAnon() and return an AnonymousAppClient to clarify the distinction with the holochain client-- especially when you're going to get a different agent pub key upon actually signing up.

Also if I don't want to allow anonymous users at all, could I disable it? Or ideally could I just call signUp() and get the actual client, and skip the whole anonymous client connection? Or am I missing something about the holo architecture?

@mattyg
Copy link
Contributor Author

mattyg commented Sep 8, 2023

For reference, this is how I'm wrapping the holo client so I only need 1 conditional to setup the holo vs holochain client:

 const client = await WebSdkApi.connect({
      chaperoneUrl: HOLO_CHAPERONE_URL,
      authFormCustomization: {
        appName: "mewsfeed",
        requireRegistrationCode: false,
      },
    });

    await new Promise((resolve) =>
      client.on("agent-state", (state: AgentState) => {
        if (state.isAvailable && state.isAnonymous) {
          client.signUp({});
        } else if (state.isAvailable && !state.isAnonymous) {
          resolve(state);
        }
      })
    );

    return client;

@mattyg
Copy link
Contributor Author

mattyg commented Oct 23, 2023

After discovering another issue with how web-sdk initializes, I have had to revise the above to:

export const setupHolo = async () => {
  try {
    const client = await WebSdkApi.connect({
      chaperoneUrl: HOLO_CHAPERONE_URL,
      authFormCustomization: {
        appName: 'my app'
        requireRegistrationCode: false,
      },
    });

    await new Promise((resolve) => {
      if (client.agentState.isAvailable && client.agentState.isAnonymous) {
        client.signUp({});
      } else if (client.agentState.isAvailable && !client.agentState.isAnonymous) {
        resolve(client.agentState);
      } else {
        client.on('agent-state', (state: AgentState) => {
          if (state.isAvailable && state.isAnonymous) {
            client.signUp({});
          } else if (state.isAvailable && !state.isAnonymous) {
            resolve(state);
          }
        });
      }
    });

    return client;
  } catch (e) {
    console.log('Holo client setup error', e);
    throw e;
  }
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants