Skip to content

@memberjunction/ng-bootstrap

MemberJunction Angular Bootstrap — encapsulates all Angular authentication and initialization logic into a single reusable module. Reduces an entire MJExplorer application module to approximately 15 lines of code.

Terminal window
npm install @memberjunction/ng-bootstrap

In MemberJunction 3.0+, Angular applications become minimal configuration files that delegate authentication, GraphQL setup, metadata loading, and user validation to this bootstrap package. The MJBootstrapModule configures all necessary providers via forRoot(), while MJBootstrapComponent serves as the root component handling the full application lifecycle from login through to the authenticated shell.

flowchart TD
    subgraph Bootstrap["MJBootstrapModule.forRoot(env)"]
        A["MJEnvironmentConfig"]
        A --> B["Auth Provider (MSAL / Auth0)"]
        A --> C["GraphQL Client + WebSocket"]
        A --> D["MJ_ENVIRONMENT Token"]
    end
    subgraph Lifecycle["MJBootstrapComponent"]
        E["Login Screen"] --> F["Authentication"]
        F --> G["Token Management"]
        G --> H["Metadata Loading"]
        H --> I["User Validation"]
        I --> J["Startup Validation"]
        J --> K["Authenticated Shell"]
    end
    subgraph States["Application States"]
        L["Not Authenticated"]
        M["Authenticated"]
        N["Error State"]
        O["Validation Banner"]
    end

    Bootstrap --> Lifecycle
    Lifecycle --> States

    style Bootstrap fill:#2d6a9f,stroke:#1a4971,color:#fff
    style Lifecycle fill:#7c5295,stroke:#563a6b,color:#fff
    style States fill:#2d8659,stroke:#1a5c3a,color:#fff
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { MJBootstrapModule, MJBootstrapComponent } from '@memberjunction/ng-bootstrap';
import { MJExplorerModule } from '@memberjunction/ng-explorer-core';
import { environment } from '../environments/environment';
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
MJBootstrapModule.forRoot(environment),
MJExplorerModule
],
bootstrap: [MJBootstrapComponent]
})
export class AppModule {}
import { MJEnvironmentConfig } from '@memberjunction/ng-bootstrap';
export const environment: MJEnvironmentConfig = {
production: false,
GRAPHQL_URI: 'http://localhost:4000/graphql',
GRAPHQL_WS_URI: 'ws://localhost:4000/graphql',
AUTH_TYPE: 'msal',
MJ_CORE_SCHEMA_NAME: '__mj',
// MSAL configuration
CLIENT_ID: 'your-client-id',
TENANT_ID: 'your-tenant-id'
// OR Auth0 configuration
// AUTH0_DOMAIN: 'yourapp.us.auth0.com',
// AUTH0_CLIENTID: 'your-auth0-client-id'
};
ConcernDescription
AuthenticationMSAL or Auth0 login/logout with token management
GraphQL setupClient configuration with WebSocket subscriptions
Token refreshAutomatic token refresh before expiration
Metadata loadingMemberJunction entity metadata and definitions
User validationAccess and permission checks
Startup validationSystem health checks on initialization
Error handlingAppropriate error messages for auth failures
NavigationInitial routing after successful login

Configures the bootstrap module with environment settings.

Parameters:

  • environment: MJEnvironmentConfig — Application configuration

Returns: ModuleWithProviders<MJBootstrapModule>

interface MJEnvironmentConfig {
production: boolean;
GRAPHQL_URI: string;
GRAPHQL_WS_URI: string;
AUTH_TYPE: 'msal' | 'auth0';
MJ_CORE_SCHEMA_NAME: string;
// MSAL-specific
CLIENT_ID?: string;
TENANT_ID?: string;
// Auth0-specific
AUTH0_DOMAIN?: string;
AUTH0_CLIENTID?: string;
}
  • MJ_ENVIRONMENT — Provides the MJEnvironmentConfig throughout the application

An optional interface for implementing custom startup validation:

interface MJStartupValidationService {
Validate(): Promise<ValidationResult>;
}

MemberJunction 2.x required ~350 lines of custom code in app.component.ts and app.module.ts for authentication and initialization. With 3.0+, this entire surface area is encapsulated in the bootstrap package:

Before (2.x)After (3.0+)
~245 lines in app.component.tsRemoved entirely
~107 lines in app.module.ts~15 lines
Custom auth logicMJBootstrapModule.forRoot(env)
Manual GraphQL setupAutomatic
Custom error handlingBuilt-in