AuthService


The AuthService provides a comprehensive API for managing all aspects of a user's account. It handles user profiles, privacy and notification settings, social interactions like following other users, and critical authentication actions such as logging out and deleting an account. You can access it through the SDK instance at sdk.auth.

This service works closely with the TokenService to manage authentication states, but abstracts away the low-level token handling for most operations.

User Profile Management#

These methods allow you to fetch, update, and manage user profile data.

getProfile#

Retrieves the complete profile for the currently authenticated user.

const profile = await sdk.auth.getProfile();
console.log(profile);

Returns

profile
Promise<object>
A promise that resolves to the user's profile object.

Example Response

{
  "did": "z8ia29UsENBg6tLZUKi2HABj38Cw1LmHZocbQ",
  "fullName": "John Doe",
  "email": "john.doe@example.com",
  "avatar": "https://example.com/avatar.png",
  "bio": "Developer and enthusiast.",
  "metadata": {}
}

saveProfile#

Updates the profile of the currently authenticated user. You can update fields like locale, metadata, and more.

Parameters

profileData
object
required
An object containing the profile fields to update.
4 subfields
const updatedProfile = await sdk.auth.saveProfile({
  metadata: { twitter: '@johndoe' },
  locale: 'en-US'
});
console.log('Profile saved:', updatedProfile);

Returns

updatedProfile
Promise<object>
A promise that resolves to the updated profile object.

getUserPublicInfo#

Fetches publicly available information for any user, identified by their DID.

Parameters

options
object
required
1 subfields
const publicInfo = await sdk.auth.getUserPublicInfo({ did: 'z8ia...' });
console.log(publicInfo.fullName);

Returns

UserPublicInfo
Promise<object>
A promise that resolves to a UserPublicInfo object.
4 subfields

refreshProfile#

Forces a synchronization of the user's profile from its original source, ensuring the data is up-to-date.

await sdk.auth.refreshProfile();
console.log('Profile refresh initiated.');

Returns

void
Promise<void>
A promise that resolves when the refresh request has been sent.

updateDidSpace#

Updates the user's DID Space configuration, which determines where their data is stored.

Parameters

options
object
required
1 subfields
const spaceGateway = {
  did: 'zNK...',
  name: 'My Personal Space',
  url: 'https://space.example.com',
  endpoint: 'https://space.example.com/api'
};

await sdk.auth.updateDidSpace({ spaceGateway });
console.log('DID Space updated successfully.');

Returns

void
Promise<void>
A promise that resolves upon successful update.

getProfileUrl#

Constructs the URL for a user's public profile page.

Parameters

options
object
required
2 subfields
const url = await sdk.auth.getProfileUrl({ did: 'z8ia...', locale: 'en' });
console.log('Profile URL:', url);

Returns

url
Promise<string>
A promise that resolves to the full profile URL string.

Settings Management#

Manage user-specific settings for privacy and notifications.

getUserPrivacyConfig#

Retrieves the privacy settings for a specified user.

Parameters

options
object
required
1 subfields
const privacyConfig = await sdk.auth.getUserPrivacyConfig({ did: 'z8ia...' });
console.log('Is email public?', privacyConfig.isEmailPublic);

Returns

PrivacyConfig
Promise<object>
A promise that resolves to the user's PrivacyConfig object, where keys are setting names and values are booleans.

saveUserPrivacyConfig#

Saves the privacy settings for the currently authenticated user.

Parameters

config
object
required
An object with key-value pairs representing the privacy settings.
const newConfig = { isEmailPublic: false, allowFriendRequests: false };
const savedConfig = await sdk.auth.saveUserPrivacyConfig(newConfig);
console.log('Privacy config saved.');

Returns

PrivacyConfig
Promise<object>
A promise that resolves to the saved PrivacyConfig object.

getUserNotificationConfig#

Gets the notification configuration for the current user, including webhooks and channel preferences.

const notificationConfig = await sdk.auth.getUserNotificationConfig();
console.log('Webhooks:', notificationConfig.webhooks);

Returns

NotificationConfig
Promise<object>
A promise that resolves to the NotificationConfig object.
2 subfields

saveUserNotificationConfig#

Saves new notification settings for the current user.

Parameters

config
object
required
The new notification configuration object.
2 subfields
const newConfig = {
  webhooks: [
    { type: 'api', url: 'https://example.com/webhook' }
  ],
  notifications: {
    email: true,
    wallet: false
  }
};
const savedConfig = await sdk.auth.saveUserNotificationConfig(newConfig);
console.log('Notification config saved:', savedConfig);

Returns

NotificationConfig
Promise<object>
A promise that resolves to the saved NotificationConfig object.

testNotificationWebhook#

Tests a webhook configuration to ensure it can receive test notifications.

Parameters

webhook
object
required
The webhook object to test.
2 subfields
const webhookToTest = {
  type: 'slack',
  url: 'https://hooks.slack.com/services/...'
};
const result = await sdk.auth.testNotificationWebhook(webhookToTest);
console.log('Webhook test successful:', result.success);

Returns

result
Promise<object>
A promise that resolves to an object with a success property.
1 subfields

Social Interactions#

Manage social connections between users.

followUser#

Follow another user.

Parameters

options
object
required
1 subfields
const userToFollow = 'z8ia...';
await sdk.auth.followUser({ userDid: userToFollow });
console.log(`Successfully followed ${userToFollow}.`);

Returns

void
Promise<void>
A promise that resolves when the operation is complete.

unfollowUser#

Unfollow a user.

Parameters

options
object
required
1 subfields
const userToUnfollow = 'z8ia...';
await sdk.auth.unfollowUser({ userDid: userToUnfollow });
console.log(`Successfully unfollowed ${userToUnfollow}.`);

Returns

void
Promise<void>
A promise that resolves when the operation is complete.

isFollowingUser#

Check if the current user is following a specific user.

Parameters

options
object
required
1 subfields
const userToCheck = 'z8ia...';
const { isFollowing } = await sdk.auth.isFollowingUser({ userDid: userToCheck });
if (isFollowing) {
  console.log(`You are following ${userToCheck}.`);
} else {
  console.log(`You are not following ${userToCheck}.`);
}

Returns

result
Promise<object>
A promise that resolves to an object containing an isFollowing property.
1 subfields

Authentication & Account Actions#

Perform critical actions related to the user's session and account lifecycle.

logout#

Logs the current user out. It can be configured to log out from a specific device or all sessions.

Parameters

options
object
3 subfields
// Simple logout from the current session
await sdk.auth.logout({});
console.log('Logged out successfully.');

// Log out from a specific device and all federated apps
await sdk.auth.logout({ visitorId: 'some-visitor-id', includeFederated: true });

Returns

void
Promise<void>
A promise that resolves when the logout process is complete.

destroyMyself#

Permanently deletes the currently authenticated user's account. This action is irreversible and should be used with extreme caution.

// This is a destructive action. Usually, you would confirm this with the user.
try {
  const result = await sdk.auth.destroyMyself();
  console.log(`Account ${result.did} has been permanently deleted.`);
} catch (error) {
  console.error('Failed to delete account:', error);
}

Returns

result
Promise<object>
A promise that resolves to an object containing the DID of the deleted user.
1 subfields