react-antd-admin-panel
Version:
Modern TypeScript-first React admin panel builder with Ant Design 6
71 lines • 1.87 kB
TypeScript
import type { User } from '../types';
type UserSubscriber = (user: User | null) => void;
/**
* UserState - Manages authenticated user state
* Provides reactive user context with subscriptions
*
* @example
* const userState = new UserState();
* userState.set({ id: 1, name: 'John', email: 'john@example.com', role: 'admin' });
* userState.subscribe((user) => console.log('User changed:', user));
* userState.hasPermission('users.create');
*/
export declare class UserState {
private _user;
private _subscribers;
/**
* Get the current user
*/
get(): User | null;
/**
* Set the current user
*/
set(user: User | null): void;
/**
* Update user properties
*/
update(updates: Partial<User>): void;
/**
* Clear the current user (logout)
*/
clear(): void;
/**
* Check if a user is authenticated
*/
isAuthenticated(): boolean;
/**
* Check if user has a specific role
*/
hasRole(role: string): boolean;
/**
* Check if user has any of the specified roles
*/
hasAnyRole(roles: string[]): boolean;
/**
* Check if user has a specific permission
*/
hasPermission(permission: string): boolean;
/**
* Check if user has all specified permissions
*/
hasAllPermissions(permissions: string[]): boolean;
/**
* Check if user has any of the specified permissions
*/
hasAnyPermission(permissions: string[]): boolean;
/**
* Get a user property
*/
getProperty<K extends keyof User>(key: K): User[K] | undefined;
/**
* Subscribe to user changes
* Returns an unsubscribe function
*/
subscribe(callback: UserSubscriber): () => void;
/**
* Notify all subscribers
*/
private _notifySubscribers;
}
export {};
//# sourceMappingURL=UserState.d.ts.map