Profile
The Profile
class provides methods to interact with user profiles in the HandCash Connect SDK.
Initialize the User Account
After the user authorizes your application, initialize their account using the authentication token:
import HandcashConnect from '@handcash/handcash-connect';
const handCashConnect = new HandcashConnect({
appId: 'YOUR_APP_ID',
appSecret: 'YOUR_APP_SECRET',
});
const account = handCashConnect.getAccountFromAuthToken('<authToken>');
Methods
getCurrentProfile()
Retrieves the full profile of the current user, including both public and private information.
async getCurrentProfile(): Promise<UserProfile>
Returns: A promise that resolves to the user’s full profile.
Example:
const profile = await account.profile.getCurrentProfile();
console.log(`Welcome, ${profile.publicProfile.displayName}!`);
Types:
type UserPublicProfile = {
id: string;
handle: string;
paymail: string;
displayName: string;
avatarUrl: string;
createdAt: Date;
};
type UserPrivateProfile = {
email: string;
};
Response Type:
Field | Type | Description |
---|---|---|
publicProfile | UserPublicProfile | Public information about the user |
privateProfile | UserPrivateProfile | Private information about the user |
getPublicProfilesByHandle(handles)
Retrieves the public profiles of HandCash users by their handles.
async getPublicProfilesByHandle(handles: string[]): Promise<UserPublicProfile[]>
handles
: An array of user handles.
Returns: A promise that resolves to an array of user public profiles.
Example:
const handles = ['user1', 'user2'];
const publicProfiles = await account.profile.getPublicProfilesByHandle(handles);
publicProfiles.forEach(profile => console.log(profile.displayName));
Response Type:
Field | Type | Description |
---|---|---|
id | string | Unique identifier for the user |
handle | string | User’s HandCash handle |
paymail | string | User’s paymail address |
displayName | string | User’s display name |
avatarUrl | string | URL of the user’s avatar image |
createdAt | Date | Date when the profile was created |
getFriends()
Retrieves a list of the user’s friends and their public profiles. Requires the FRIENDS
permission.
async getFriends(): Promise<UserPublicProfile[]>
Returns: A promise that resolves to an array of public profiles of the user’s friends.
Example:
const friends = await account.profile.getFriends();
console.log(`You have ${friends.length} friends.`);
Response Type:
Field | Type | Description |
---|---|---|
(Same as UserPublicProfile) |
getPermissionsInfo()
Retrieves the permissions granted to the app by the user, along with the app ID.
async getPermissionsInfo(): Promise<PermissionInfo>
Returns: A promise that resolves to an object containing the permissions and app ID.
Permission Enum:
enum Permission {
Pay = 'PAY',
UserPublicProfile = 'USER_PUBLIC_PROFILE',
UserPrivateProfile = 'USER_PRIVATE_PROFILE',
Friends = 'FRIENDS',
Decrypt = 'DECRYPT',
ReadBalance = 'READ_BALANCE',
}
Example:
const permissionsInfo = await account.profile.getPermissionsInfo();
console.log(`App ID: ${permissionsInfo.appId}`);
console.log('Permissions:', permissionsInfo.items);
Response Type:
Field | Type | Description |
---|---|---|
items | Permission[] | Array of Permission enum values |
appId | string | Unique identifier for the app |
Types
The SDK uses several TypeScript types for representing user profiles, permissions, and other data. Here are some key types:
UserProfile
: Combines public and private profile information.UserPublicProfile
: Contains publicly accessible user information.UserPrivateProfile
: Contains private user information.PermissionInfo
: Contains permissions and app ID.
For more detailed information on these types, refer to the SDK’s type definitions.