0 directories, 46 files

util

Home / tinai / util
/**
 * Shared localStorage key helpers for multi-user authentication storage.
 * Kept separate from Storage to avoid a circular import with api.js.
 */

const KEY_ACTIVE_USER_ID = 'ACTIVE_USER_ID';

/**
 * Returns the localStorage key for an authentication-related value,
 * scoped to the active user, or the unscoped base key when no user is active.
 * @param {string} baseKey - Base key name (e.g. 'AUTH_TOKEN').
 * @returns {string} The localStorage key to read or write.
 */
export function get_auth_storage_key(baseKey) {
	const activeUserId = (typeof localStorage !== 'undefined') ? localStorage.getItem(KEY_ACTIVE_USER_ID) : null;
	return activeUserId ? `${activeUserId}_${baseKey}` : baseKey;
}

export { KEY_ACTIVE_USER_ID };
🌐
auth-storage.js ×
Type: Web, text/plain
735 Bytes
Last Modified 2026-11-04 09:48:28
⬇ Download File