Are Principals unique?

I am trying to set a uniqueId created after a user signs in from their Principal.

However, every time I login and logout a new Principal is issues resulting in multiple account creations.

    const stored = localStorage.getItem("ic-identity");
    if (stored) {
      const identity = Ed25519KeyIdentity.fromJSON(stored);
      const res = await run.counter.addAccount(identity.getPrincipal()).catch(err => {
      })
      console.log(res)

In Motoko:

    public type UserData = {
      id: Principal;
    };

This all saves correctly other than that the Principal changes each time I login and out.
What is the correct way to generate a unique ID after signin?

This almost has it, but does not show how to pass the unique id from the frontend. journey/main.mo at 8a0e45c4dee8f3f786ff7a7880e8bc8a10811144 · hansl/journey · GitHub

You’ll need to pass the identity into the HttpAgent when it’s initialized like we do here in my auth client demo:

1 Like

Works like magic!

    public shared (msg) func addAccount(): async UserData {
        var account = await findAccount(msg.caller);
1 Like