Author
Blog by Frontend Team
All blog posts written by Frontend Team.

JavaScript SDK Reference

Comprehensive reference for the JavaScript SDK with TypeScript support.

Installation

npm install @authcompany/js-sdk

Initialization

import { AuthClient } from '@authcompany/js-sdk';

const auth = new AuthClient({
  clientId: string;
  domain: string;
  redirectUri?: string;
  audience?: string;
  scope?: string;
});

Core Methods

loginWithRedirect()

Initiates login flow with redirect.

await auth.loginWithRedirect({
  appState?: any;
  loginHint?: string;
});

getUser()

Retrieves authenticated user profile.

const user = await auth.getUser();
// Returns: User | null

handleRedirectCallback()

Processes authentication callback.

const result = await auth.handleRedirectCallback();
// Returns: { appState?: any }

Events

auth.on('authenticated', (user) => {
  console.log('User logged in:', user);
});

For advanced usage and configuration, see our advanced guides.

Branding and UI Customization

Customize the authentication UI to provide a seamless branded experience.

Basic Branding

{
  "branding": {
    "logo": "https://yourcompany.com/logo.png",
    "favicon": "https://yourcompany.com/favicon.ico",
    "colors": {
      "primary": "#007bff",
      "secondary": "#6c757d",
      "background": "#ffffff",
      "text": "#333333"
    },
    "font": {
      "family": "Inter, sans-serif",
      "url": "https://fonts.googleapis.com/css2?family=Inter"
    }
  }
}

Custom CSS

.auth-container {
  border-radius: 12px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.auth-button {
  background: var(--primary-color);
  transition: all 0.3s ease;
}

.auth-button:hover {
  transform: translateY(-2px);
}

Email Templates

<div style="font-family: {{font.family}};">
  <img src="{{logo}}" alt="Logo" />
  <h1 style="color: {{colors.primary}};">
    Welcome to {{companyName}}
  </h1>
  <p>Please verify your email address.</p>
</div>

Advanced Customization

auth.customize({
  theme: 'dark',
  components: {
    loginButton: CustomLoginButton,
    signupForm: CustomSignupForm
  },
  hooks: {
    beforeRender: (context) => {
      // Custom logic
    }
  }
});

For white-labeling options, see our enterprise customization guide.