AuthClient return anonymous Identity instead of logged in

when logging in, i get this in my browser and the returned identity is anonymous instead of the logged in user

WARNING: expected origin ‘https://identity.ic0.app’, got ‘https://XXXX-XXXXX-aaaan-qmbfq-cai.icp0.io’ (ignoring)

how to solve?

my code:

async function loginScript (event)
{

event.preventDefault();

let authClient = await AuthClient.create();
// start the login process and wait for it to finish
await new Promise((resolve) => {
    authClient.login({
        identityProvider:
            process.env.DFX_NETWORK === "ic"
                ? "https://identity.ic0.app"
                : `http://rdmx6-jaaaa-aaaaa-aaadq-cai.localhost:4943`,
        onSuccess: resolve ,
    });
});
const identity = authClient.getIdentity();
console.log(identity);

const agent = new HttpAgent({ identity });
actor = await createActor(process.env.CANISTER_ID_DCE_BACKEND, {
    agent,
});

I think you need to specify the host in the HttpAgent to point to localhost

SOLVED: i mixed up two examples, solved now :man_facepalming:

Hi,

I’m getting the same issue. When I try to login, a new tab opens and I login with my test internet identity. It then closes the tab and comes back to the tab that I started on, but then nothing: I am not authenticated and all I get is this warning log

WARNING: expected origin 'http://a3shf-5eaaa-aaaaa-qaafa-cai.localhost:4943', got 'http://localhost:3000' (ignoring)

N.B: http://a3shf-5eaaa-aaaaa-qaafa-cai.localhost:4943 is the frontend of my internet identity canister, whereas http://localhost:3000 is the frontend canister of my app.

@richards Can I ask how you solved your issue ? (my code looks very much like yours)
@anon74414410 it’s coming from this file that you wrote. Basically this warning is stopping the authentication request and I’m not sure what it’s trying to prevent :blush: :pray:

Thanks!

I think this warning is a false negative and won’t be the real issue you’re facing. Because we have to listen for window messages, any message fired on window will trigger the callback. There are plenty of reasons there may be messages, and this could include browser extensions.

We only want to respond to messages originating from the identity provider. For example, this warning fires a lot during development from React Devtools while we are waiting for a response. It shouldn’t be breaking your app if you have correctly set up the identity provider and managed your async behavior to ensure the identity check fires after the login onSuccess call has fired

1 Like

Thanks a lot. You were right: the warning wasn’t the issue (hence why it’s just a warning I guess :smile:).

The error was later in my code, in the part I was using to check if login worked or not! So it was working all along, only I thought it wasn’t… :face_with_open_eyes_and_hand_over_mouth:

1 Like