useDeId
This hook allows you to access various data and helper functions associated to de[id].
You need to have DeIdContext properly set up for this hook to work.
Usage
import { useDeId } from '@dustlabs/profiles/core';
const { profile } = useDeId();Return Value
{
address: string | undefined;
isConnected: boolean;
profileParams: ProfileParams;
verifyParams: VerifyParams;
handleChangeProfileParams: (profileParams: ProfileParams) => void;
authAccess: <T extends [] | unknown[], U>(
fn: (signInData: SignInData, ...args: T) => U,
options?: AuthAccessOptions
) => (...args: T) => Promise<U | undefined>;
isLoadingAuthentication: boolean;
isSignedIn: boolean;
signIn: () => Promise<void | undefined>;
signOut: (signOutOptions?: SignOutOptions) => void;
signInCallback: (
profile: Profile,
accessToken: string,
refreshToken: string,
externalSignInProvider?: IdentityProviderName
) => Promise<void>;
externalSignInProvider: IdentityProviderName | null;
profile: Profile | null;
isLoadingProfile: boolean;
holdings: ProfileHeldCollection[];
syncCurrentProfile: (options?: SyncProfileOptions) => Promise<{
profileHoldings: ProfileHeldCollection[];
}>;
isReady: boolean;
profileSummary: ProfileSummary | undefined;
isLoadingProfileSummary: boolean;
refetchProfileSummary: () => Promise<
ApolloQueryResult<ProfileData<"profileSummary">> | undefined
>;
accessToken: string | null;
refreshToken: string | null;
sessionId: string;
}address
string | undefined
The address of the currently connected wallet (if any).
isConnected
boolean
Whether or not the user connected a web3 wallet.
profileParams
Current profile params. This is used for querying, and will always have a value regardless of whether the user has connected a wallet. If the user signed in using socials, this value will be a wallet linked to their de[id] that matches the current chain context.
verifyParams
Current verify params. This is used for wallet verification.
handleChangeProfileParams
(profileParams: ProfileParams) => void
A function that allows you to update the current profile params.
authAccess
<T extends [] | unknown[], U>(fn: (signInData: SignInData, ...args: T) => U, options?: AuthAccessOptions) => (...args: T) => Promise<U | undefined>
This is a higher order function that allows you to wrap a function that requires authentication. If the user is not signed in, it will prompt them to sign in / refresh sign in. If the user is signed in, it will call the function with the current SignInData and any arguments passed to the returned function.
isLoadingAuthentication
boolean
The authentication loading state of the user.
isSignedIn
boolean
Whether or not the user is signed in.
signIn
() => Promise<void | undefined>
A function that triggers user sign in.
signOut
(signOutOptions?: SignOutOptions) => void
A function that triggers user sign out. This function takes in SignOutOptions as an argument.
signInCallback
(profile: Profile, accessToken: string, refreshToken: string, externalSignInProvider?: IdentityProviderName) => Promise<void>
This function is used to update the values in the context if you already have the tokens and profile object from other means (such as from from merging profiles). This is used internally by the library, but can be used to trigger custom logic to update the context.
externalSignInProvider
The external sign in provider that was used to sign in the user (if any).
profile
The profile object of the currently signed in user (if any).
isLoadingProfile
boolean
The profile loading state of the user.
holdings
The holdings of the currently signed in user (if any). This is a filtered list based on what was provided in the projects field of the DeIdProvider.
syncCurrentProfile
(options?: SyncProfileOptions) => Promise<{ profileHoldings: ProfileHeldCollection[] }>
A function that triggers a sync of the current profile. This will update the profile object in the context, as well as the holdings. This function takes in SyncProfileOptions as an argument.
isReady
boolean
Whether signed in state is initialized.
Reason: When user refreshes, signed in state is defaulted to false, so if you
were to check for isSignedIn when user refresh, it will be wrongly false even
if the user has valid tokens. Hence with this, you can check isSignedIn && isReady.
profileSummary
The profile summary of the currently signed in user (if any). Will trigger when any wallet is connected.
isLoadingProfileSummary
boolean
The profile summary loading state of the user.
refetchProfileSummary
() => Promise<ApolloQueryResult<ProfileData<"profileSummary">> | undefined>
A function that triggers a refetch of the profile summary.
accessToken
string | null
The access token of the currently signed in user (if any).
refreshToken
string | null
The refresh token of the currently signed in user (if any).
sessionId
string
The session id of the currently signed in user (if any).