UNPKG

@asgardeo/nextjs

Version:

Next.js implementation of Asgardeo JavaScript SDK.

92 lines (91 loc) 4.96 kB
/** * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com). * * WSO2 LLC. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except * in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import { AsgardeoNodeClient, EmbeddedFlowExecuteRequestPayload, EmbeddedFlowExecuteResponse, SignInOptions, SignOutOptions, SignUpOptions, User, UserProfile, Organization, EmbeddedSignInFlowHandleRequestPayload, EmbeddedFlowExecuteRequestConfig, ExtendedAuthorizeRequestUrlParams, IdToken, CreateOrganizationPayload, OrganizationDetails, AllOrganizationsApiResponse, TokenResponse, Storage, TokenExchangeRequestConfig } from '@asgardeo/node'; import { AsgardeoNextConfig } from './models/config'; /** * Client for mplementing Asgardeo in Next.js applications. * This class provides the core functionality for managing user authentication and sessions. * * This class is implemented as a singleton to ensure a single instance across the application. * * @typeParam T - Configuration type that extends AsgardeoNextConfig. */ declare class AsgardeoNextClient<T extends AsgardeoNextConfig = AsgardeoNextConfig> extends AsgardeoNodeClient<T> { private static instance; private asgardeo; isInitialized: boolean; private constructor(); /** * Get the singleton instance of AsgardeoNextClient */ static getInstance<T extends AsgardeoNextConfig = AsgardeoNextConfig>(): AsgardeoNextClient<T>; /** * Ensures the client is initialized before using it. * Throws an error if the client is not initialized. */ private ensureInitialized; initialize(config: T, storage?: Storage): Promise<boolean>; reInitialize(config: Partial<T>): Promise<boolean>; getUser(userId?: string): Promise<User>; getUserProfile(userId?: string): Promise<UserProfile>; updateUserProfile(payload: any, userId?: string): Promise<User>; createOrganization(payload: CreateOrganizationPayload, userId?: string): Promise<Organization>; getOrganization(organizationId: string, userId?: string): Promise<OrganizationDetails>; getMyOrganizations(options?: any, userId?: string): Promise<Organization[]>; getAllOrganizations(options?: any, userId?: string): Promise<AllOrganizationsApiResponse>; getCurrentOrganization(userId?: string): Promise<Organization | null>; switchOrganization(organization: Organization, userId?: string): Promise<TokenResponse | Response>; isLoading(): boolean; isSignedIn(sessionId?: string): Promise<boolean>; exchangeToken(config: TokenExchangeRequestConfig, sessionId?: string): Promise<TokenResponse | Response>; /** * Gets the access token from the session cookie if no sessionId is provided, * otherwise falls back to legacy client method. */ getAccessToken(sessionId?: string): Promise<string>; /** * Get the decoded ID token for a session */ getDecodedIdToken(sessionId?: string, idToken?: string): Promise<IdToken>; getConfiguration(): T; signIn(options?: SignInOptions, sessionId?: string, onSignInSuccess?: (afterSignInUrl: string) => void): Promise<User>; signIn(payload: EmbeddedSignInFlowHandleRequestPayload, request: EmbeddedFlowExecuteRequestConfig, sessionId?: string, onSignInSuccess?: (afterSignInUrl: string) => void): Promise<User>; signOut(options?: SignOutOptions, afterSignOut?: (afterSignOutUrl: string) => void): Promise<string>; signOut(options?: SignOutOptions, sessionId?: string, afterSignOut?: (afterSignOutUrl: string) => void): Promise<string>; signUp(options?: SignUpOptions): Promise<void>; signUp(payload: EmbeddedFlowExecuteRequestPayload): Promise<EmbeddedFlowExecuteResponse>; signInSilently(options?: SignInOptions): Promise<User | boolean>; /** * Gets the sign-in URL for authentication. * Ensures the client is initialized before making the call. * * @param customParams - Custom parameters to include in the sign-in URL. * @param userId - The user ID * @returns Promise that resolves to the sign-in URL */ getAuthorizeRequestUrl(customParams: ExtendedAuthorizeRequestUrlParams, userId?: string): Promise<string>; /** * Gets the storage manager from the underlying Asgardeo client. * Ensures the client is initialized before making the call. * * @returns Promise that resolves to the storage manager */ getStorageManager(): Promise<any>; clearSession(): Promise<void>; } export default AsgardeoNextClient;