Skip to main content

Account Management

The @archibald/cdc package provides a CDCAccountsService for managing user accounts in SAP Customer Data Cloud (CDC).

CDCAccountsService

The CDCAccountsService provides a set of methods for interacting with the CDC accounts API. This service is automatically registered when you use the CDCUserAuthProvider. You can inject it into your custom services or controllers to perform account management operations.

Usage

Here is a high-level example of how you might use the CDCAccountsService in a custom controller to get the current user's account information:

import { CDCAccountsService } from '@archibald/cdc';
import { getSession } from '@archibald/auth';
import { Inject, BaseController } from '@archibald/server';
import type { Request, ResponseToolkit } from '@hapi/hapi';

export class AccountController extends BaseController {
@Inject()
private readonly cdcAccountsService: CDCAccountsService;

constructor() {
super('AccountController');
}

public async getAccountInfo(request: Request, h: ResponseToolkit) {
const { user } = getSession();

try {
// user.id in Archibald typically maps to the CDC UID
const accountInfo = await this.cdcAccountsService.getAccountInfo({ UID: user.id });
return h.response(accountInfo).code(200);
} catch (error) {
// ... handle error
return h.response({ error: '...' }).code(500);
}
}
}

And how you would configure the route for this controller:

// src/server/routes/account.ts
import { type DefaultRouteConfig, RouteMethod } from '@archibald/core';

const AccountServerRouteConfig: DefaultRouteConfig[] = [
{
method: RouteMethod.GET,
path: 'account',
handler: 'AccountController.getAccountInfo',
options: {
auth: {
strategy: 'jwt',
mode: 'required'
},
description: 'Gets account data for user',
tags: ['api', 'Account']
}
}
];

export default AccountServerRouteConfig;

Available Methods

The CDCAccountsService provides a wide range of methods for managing user accounts, including:

  • getAccountInfo: Get the account information for a user.
  • setAccountInfo: Set the account information for a user.
  • login: Log in a user.
  • logout: Log out a user.
  • register: Register a new user.
  • resetPassword: Reset a user's password.
  • getJWT: Get a JWT for a user.

For a complete list of available methods, please refer to the source code of the CDCAccountsService in the @archibald/cdc package.