Skip to main content

AuthenticationManager

Datalayer Core


Datalayer Core / AuthenticationManager

Class: AuthenticationManager

Defined in: src/client/auth/AuthenticationManager.ts:30

Authentication Manager for Datalayer SDK Provides a unified interface for all authentication methods

Constructors

Constructor

new AuthenticationManager(iamRunUrl, storage?): AuthenticationManager

Defined in: src/client/auth/AuthenticationManager.ts:42

Create an AuthenticationManager instance

Parameters

iamRunUrl

string

IAM service URL (e.g., "https://prod1.datalayer.run")

storage?

TokenStorage

Token storage backend (optional, defaults to auto-detected)

Returns

AuthenticationManager

Methods

clearStoredToken()

clearStoredToken(): void

Defined in: src/client/auth/AuthenticationManager.ts:218

Clear the stored token

Returns

void


getCurrentToken()

getCurrentToken(): string | undefined

Defined in: src/client/auth/AuthenticationManager.ts:237

Get the current token

Returns

string | undefined

Current token or undefined


getCurrentUser()

getCurrentUser(): User | undefined

Defined in: src/client/auth/AuthenticationManager.ts:229

Get the current cached user

Returns

User | undefined

Current user or undefined


getStoredToken()

getStoredToken(): string | null

Defined in: src/client/auth/AuthenticationManager.ts:197

Get the stored token from storage

Returns

string | null

Stored token or null


isAuthenticated()

isAuthenticated(): boolean

Defined in: src/client/auth/AuthenticationManager.ts:245

Check if user is currently authenticated

Returns

boolean

True if user is authenticated


login()

login(options): Promise<AuthResult>

Defined in: src/client/auth/AuthenticationManager.ts:91

Login using various authentication methods Automatically selects the appropriate strategy based on options

Parameters

options

AuthOptions = {}

Authentication options

Returns

Promise<AuthResult>

Authentication result with user and token

Throws

Error if authentication fails or no suitable strategy found

Examples

// Token-based auth
const result = await auth.login({ token: 'abc123' });
// Credentials-based auth
const result = await auth.login({
handle: 'user@example.com',
password: 'secret'
});
// Storage-based auth (uses stored token)
const result = await auth.login({});

logout()

logout(): Promise<void>

Defined in: src/client/auth/AuthenticationManager.ts:123

Logout the current user Calls the logout API and clears stored tokens

Returns

Promise<void>


storeToken()

storeToken(token): void

Defined in: src/client/auth/AuthenticationManager.ts:208

Store a token in storage

Parameters

token

string

Token to store

Returns

void


validateToken()

validateToken(token): Promise<TokenValidationResult>

Defined in: src/client/auth/AuthenticationManager.ts:178

Validate a token Checks if a token is valid by attempting to get the user profile

Parameters

token

string

Token to validate

Returns

Promise<TokenValidationResult>

Validation result with user if valid


whoami()

whoami(): Promise<User | null>

Defined in: src/client/auth/AuthenticationManager.ts:149

Get the current user profile Uses cached user if available, otherwise fetches from API

Returns

Promise<User | null>

Current user or null if not authenticated