createNodeAuthCallbacks
Creates onAuth and onAuthFailure callback functions compatible with @catmint-fs/git operations. These callbacks use the system's git credential helper to look up, store, and reject credentials automatically.
Import
import { createNodeAuthCallbacks } from "@catmint-fs/git-auth-node";
Signature
function createNodeAuthCallbacks(): {
onAuth: (url: string) => Promise<{ username: string; password: string } | undefined>;
onAuthFailure: (url: string, auth: { username: string; password: string }) => Promise<void>;
};
Parameters
None.
Return Value
Returns an object with two callback functions:
| Property | Type | Description |
|---|---|---|
onAuth | (url: string) => Promise<{ username: string; password: string } | undefined> | Called when authentication is needed. Looks up credentials via git credential fill. Returns credentials or undefined if none are available. On success, stores the credentials via git credential approve. |
onAuthFailure | (url: string, auth: { username: string; password: string }) => Promise<void> | Called when authentication fails. Rejects the credentials via git credential reject so the helper can remove them. |
Examples
Basic Clone
import { createNodeAuthCallbacks } from "@catmint-fs/git-auth-node";
import { clone } from "@catmint-fs/git";
import { SqliteAdapter } from "@catmint-fs/sqlite-adapter";
import { CatmintFs } from "@catmint-fs/core";
const adapter = new SqliteAdapter({ database: ":memory:" });
const fs = new CatmintFs(adapter);
const { onAuth, onAuthFailure } = createNodeAuthCallbacks();
await clone({
fs,
url: "https://github.com/my-org/private-repo.git",
dir: "/repo",
onAuth,
onAuthFailure,
});
Fetch with Authentication
import { createNodeAuthCallbacks } from "@catmint-fs/git-auth-node";
import { fetch } from "@catmint-fs/git";
const { onAuth, onAuthFailure } = createNodeAuthCallbacks();
await fetch({
fs,
dir: "/repo",
onAuth,
onAuthFailure,
});
Push with Authentication
import { createNodeAuthCallbacks } from "@catmint-fs/git-auth-node";
import { push } from "@catmint-fs/git";
const { onAuth, onAuthFailure } = createNodeAuthCallbacks();
await push({
fs,
dir: "/repo",
remote: "origin",
ref: "main",
onAuth,
onAuthFailure,
});
Behavior
- When
@catmint-fs/gitneeds credentials, it callsonAuth(url). onAuthrunsgit credential fillwith the URL's protocol and host.- If credentials are found, they are returned to
@catmint-fs/git. - If authentication succeeds, the credentials are approved via
git credential approve. - If authentication fails,
onAuthFailureis called, which runsgit credential rejectto remove the bad credentials.
