I cannot direct my implemented Internet Identity button to the correctly formatted link.
When I click on this button, it directs me to http://127.0.0.1:4943/?canisterId=rdmx6-jaaaa-aaaaa-aaadq-cai#authorize (which has several errors including not being able to load sars.js) instead of http://localhost:4943?canisterId=rdmx6-jaaaa-aaaaa-aaadq-cai#authorize.
I have implemented the following button in my NextJS application:
import { AuthClient } from "@dfinity/auth-client";
import { HttpAgent, Identity } from "@dfinity/agent";
import { useState } from "react";
export default function IIButton() {
const [newIdentity, setNewIdentity] = useState<Identity | undefined>();
async function InternetIdentityLogin(e: React.MouseEvent<HTMLButtonElement, MouseEvent>) {
e.preventDefault();
let authClient = await AuthClient.create();
await new Promise((resolve) => {
authClient.login({
identityProvider:
process.env.DFX_NETWORK === "ic"
? "https://identity.ic0.app"
: `http://localhost:4943/?canisterId=rdmx6-jaaaa-aaaaa-aaadq-cai`,
onSuccess: () => resolve,
});
});
const identity = authClient.getIdentity();
if (identity) {
setNewIdentity(identity);
}
const agent = new HttpAgent({ identity });
return agent;
}
return (
<div className="flex w-1/2 mb-4">
{!newIdentity ? <button onClick={async (e) => { await InternetIdentityLogin(e) }} className="btn btn-primary">Login to Internet Identity</button> :
<span className="badge">{newIdentity.toString()}</span>}
</div>
);
};
I have also updated my dfx.json so that the local servers are bind to localhost:4943:
"networks": {
"local": {
"bind": "localhost:4943",
"type": "ephemeral"
}
}
What am I doing wrong?