Mogh Auth Client

raw JSON →
1.3.0 verified Sat Apr 25 auth: no javascript

Mogh Auth Client is a TypeScript library for authenticating with the Mogh authentication service, version 1.3.0. It supports token-based authentication and session management. The package ships with TypeScript types and is intended for use in Node.js or browser environments. It is maintained by the MoghTech team with a focus on security and ease of integration.

error Error: Cannot find module 'axios'
cause Axios is a peer dependency that is not automatically installed.
fix
Run 'npm install axios' in your project.
error TypeError: client.authenticate is not a function
cause Using default import instead of named import, resulting in undefined class method.
fix
Use import { MoghAuthClient } from 'mogh_auth_client'.
error HttpError: 401 Unauthorized
cause API key is invalid or not provided.
fix
Check that the apiKey in constructor is correct and set via environment variable.
breaking In v1.3.0, the constructor options changed: 'apiKey' replaced 'clientId'. Old code using 'clientId' will fail.
fix Update constructor call: new MoghAuthClient({ apiKey: '...' }) instead of { clientId: '...' }.
deprecated The 'authenticate' method's callback style is deprecated. Use async/await or Promises as of v1.2.0.
fix Replace callbacks with async/await: const result = await client.authenticate(...).
gotcha The package requires axios as a peer dependency but does not list it in 'dependencies' in package.json. If axios is not installed, runtime error occurs.
fix Install axios: npm install axios
gotcha The 'endpoint' option must not have a trailing slash. Including it may cause unexpected 404 errors.
fix Ensure endpoint is like 'https://auth.mogh.io/v1' without trailing slash.
npm install mogh_auth_client
yarn add mogh_auth_client
pnpm add mogh_auth_client

Creates a MoghAuthClient instance and authenticates a user with email and password, then logs the access token.

import { MoghAuthClient } from 'mogh_auth_client';

const client = new MoghAuthClient({
  apiKey: process.env.MOGH_API_KEY ?? '',
  endpoint: 'https://auth.mogh.io/v1'
});

async function authenticate() {
  try {
    const result = await client.authenticate({
      username: 'user@example.com',
      password: 'securepassword'
    });
    console.log('Access Token:', result.accessToken);
  } catch (error) {
    console.error('Auth failed:', error);
  }
}

authenticate();