@nfid/embed
Integration
Authentication

Authentication

Check if the user is authenticated

You can hack it with the nfid.isAuthenticated property. If true the user is already authenticated and you can request the delegation identity directly without user interaction from nfid.getIdentity():

import { Identity } from "@dfinity/agent"
 
const identity: Identity = nfid.getIdentity()

If not, prepare the Identity package from @dfinity/agent and open the NFID Wallet auth modal when a user needs to authenticate with nfid.getDelegation():

import { Identity } from "@dfinity/agent";
 
const delegationIdentity: Identity = await nfid.getDelegation({
  // optional targets ICRC-28 implementation, but required to support universal NFID Wallet auth
  targets: ["YOUR_CANISTER_ID_1", "YOUR_CANISTER_ID_2", "ETC"],
  // optional derivationOrigin in case you're running on a custom domain
  derivationOrigin, "https://<canister_id>.ic0.app",
  // optional maxTimeToLive defaults to 8 hours in nanoseconds;
  maxTimeToLive: BigInt(8) * BigInt(3_600_000_000_000)
});

The ICRC-28 will describe the method YOUR_CANISTER_ID_1, YOUR_CANISTER_ID_2, and ETC canisters should have implemented.

See more detailed information on using custom domains with the derivationOrigin.

Check if delegation is universal or anonymous

When a user authenticates, you can use nfid.getDelegationType() to see if the authenticated wallet is universal or anonymous.

enum DelegationType {
  GLOBAL = 0,
  ANONYMOUS = 1,
}
 
const delegationType: DelegationType = nfid.getDelegationType()