---
editLink: false
lastUpdated: false
---

[@salesforce/b2c-tooling-sdk](../../modules.md) / [cli](../index.md) / AuthSessionStoreHook

# Type Alias: AuthSessionStoreHook

> **AuthSessionStoreHook** = `Hook`\<`"b2c:auth-session-store"`\>

Defined in: [packages/b2c-tooling-sdk/src/cli/hooks.ts:407](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/b7ec7d4a1464ef7bbb6a5757ffd6f99a18a31bf6/packages/b2c-tooling-sdk/src/cli/hooks.ts#L407)

Hook type for `b2c:auth-session-store`.

Implement this hook in your oclif plugin to store auth sessions somewhere
other than the default file in the CLI data directory, such as an OS
keychain or a secrets manager.

The hook is called during command initialization, before any
authentication is performed. Only one store is used: if several plugins
return a backend, the first plugin by name wins and the others are ignored
with a warning.

[AuthSessionBackend](../../auth/interfaces/AuthSessionBackend.md) is synchronous because session lookups happen
while commands initialize. Backends over async storage should load their
sessions inside the hook (which may be async), serve reads from memory,
write in the background, and implement `flush()` so the CLI can wait for
pending writes before exiting.

## Plugin Registration

```json
{
  "oclif": {
    "hooks": {
      "b2c:auth-session-store": "./dist/hooks/auth-session-store.js"
    }
  }
}
```

## Example

```typescript
import type { AuthSessionStoreHook } from '@salesforce/b2c-tooling-sdk/cli';

const hook: AuthSessionStoreHook = async function() {
  if (process.platform !== 'darwin') return {};
  return { backend: new KeychainAuthSessionBackend() };
};

export default hook;
```
