import { BasedServer } from '../server.js'; import { Context, AuthState, WebSocketSession, Authorize, AuthorizeConnection, VerifyAuthState } from '@based/functions'; import parseAuthState from './parseAuthState.js'; import parseJSONAuthState from './parseJSONAuthState.js'; export { parseAuthState }; export { parseJSONAuthState }; export type AuthConfig = { /** This function is called before any BasedFunction that isn't public. * The BasedFunction requested will only execute if `authorize` returns `true`. */ authorize?: Authorize; authorizeConnection?: AuthorizeConnection; /** This function is called every time an authState is set. * @returns `true` if the authState is valid and does not need to be updated * @returns `AuthState` object if the authState of the session needs to be updated */ verifyAuthState?: VerifyAuthState; }; export declare class BasedAuth { server: BasedServer; authorizeConnection: AuthorizeConnection; verifyAuthState: VerifyAuthState; authorize: Authorize; constructor(server: BasedServer, config?: AuthConfig); updateConfig(config: AuthConfig): void; /** Calls `verifyAuthState` on the current session's authState. * If it's in a wsContext, sends the new verified authState to the client and updates the session's authState. */ renewAuthState(ctx: Context, authState?: AuthState): Promise; encodeAuthState(authState: AuthState): string; decodeAuthState(authState: any): AuthState; /** Sets the `authState` on the client. */ sendAuthState(ctx: Context, authState: AuthState): void; }