The authClient.getIdentity()
method returns a DelegationIdentity
(which extends a SignIdentity
) if the login process has been completed successfully.
So, you just need to cast the type:
_identity = authClient.getIdentity() as DelegationIdentity; // or: as SignIdentity
We do something similar here:
}
const accountId = AccountIdentifier.fromPrincipal({ principal: identity.getPrincipal() });
setLedgerData((prev) => ({ ...prev, accountId, isLoading: true }));
const balanceE8s = await ledgerCanister.accountBalance({ accountIdentifier: accountId });
setLedgerData((prev) => ({ ...prev, accountId, balanceE8s, isLoading: false }));
}, [ledgerCanister, identity]);
const setContext = useCallback(async (authClient: AuthClient): Promise<[DelegationIdentity, BackendActor]> => {
const id = authClient.getIdentity() as DelegationIdentity;
setIdentity(id);
const actor = await createBackendActor(id);
setBackendActor(actor);
const ledger = LedgerCanister.create({
agent: await createBackendAgent(id),
canisterId: LEDGER_CANISTER_ID,
});
setLedgerCanister(ledger);
Does this help?