Node.js SDK for Authdog authentication and user management.
npm install @authdog/node-sdkimport { AuthdogClient, AuthenticationError, APIError } from '@authdog/node-sdk';
// Initialize the client
const client = new AuthdogClient({
baseUrl: 'https://api.authdog.com',
apiKey: 'your-api-key', // Optional
timeout: 10000, // Optional, defaults to 10 seconds
});
// Get user information
try {
const userInfo = await client.getUserInfo('your-access-token');
console.log(`User: ${userInfo.user.displayName}`);
console.log(`Email: ${userInfo.user.emails[0].value}`);
} catch (error) {
if (error instanceof AuthenticationError) {
console.error('Authentication failed:', error.message);
} else if (error instanceof APIError) {
console.error('API error:', error.message);
} else {
console.error('Unexpected error:', error);
}
}import { AuthdogClient } from '@authdog/node-sdk';
async function getUserData(accessToken: string) {
const client = new AuthdogClient({
baseUrl: 'https://api.authdog.com',
});
try {
const userInfo = await client.getUserInfo(accessToken);
return {
id: userInfo.user.id,
name: userInfo.user.displayName,
email: userInfo.user.emails[0]?.value,
provider: userInfo.user.provider,
};
} finally {
client.close();
}
}new AuthdogClient(config: AuthdogClientConfig)Config Options:
baseUrl(string): The base URL of the Authdog APIapiKey(string, optional): API key for authenticationtimeout(number, optional): Request timeout in milliseconds (default: 10000)
Get user information using an access token.
Parameters:
accessToken(string): The access token for authentication
Returns: Promise - User information with the following structure:
interface UserInfoResponse {
meta: {
code: number;
message: string;
};
session: {
remainingSeconds: number;
};
user: {
id: string;
externalId: string;
userName: string;
displayName: string;
nickName: string | null;
profileUrl: string | null;
title: string | null;
userType: string | null;
preferredLanguage: string | null;
locale: string;
timezone: string | null;
active: boolean;
names: {
id: string;
formatted: string | null;
familyName: string;
givenName: string;
middleName: string | null;
honorificPrefix: string | null;
honorificSuffix: string | null;
};
photos: Array<{
id: string;
value: string;
type: string;
}>;
phoneNumbers: Array<any>;
addresses: Array<any>;
emails: Array<{
id: string;
value: string;
type: string | null;
}>;
verifications: Array<{
id: string;
email: string;
verified: boolean;
createdAt: string;
updatedAt: string;
}>;
provider: string;
createdAt: string;
updatedAt: string;
environmentId: string;
};
}Close the HTTP client (useful for cleanup).
AuthdogError: Base exception for all Authdog SDK errorsAuthenticationError: Raised when authentication fails (401 responses)APIError: Raised when API requests fail
# Install dependencies
npm install
# Build the project
npm run build
# Run tests
npm test
# Run tests in watch mode
npm run test:watch
# Lint code
npm run lint
# Fix linting issues
npm run lint:fix
# Format code
npm run formatThis SDK is written in TypeScript and provides full type definitions. Import types as needed:
import { UserInfoResponse, AuthdogClientConfig } from '@authdog/node-sdk';