()
| 1 | import { v4 as uuidv4 } from 'uuid'; |
| 2 | |
| 3 | export const getUserId = () => { |
| 4 | const localStorageKey = 'census_user_id'; |
| 5 | let userId = localStorage.getItem(localStorageKey); |
| 6 | |
| 7 | if (!userId) { |
| 8 | // Generate a unique ID for the user |
| 9 | userId = `${uuidv4()}_${new Date().getTime()}`; |
| 10 | |
| 11 | // Save the user ID in local storage |
| 12 | localStorage.setItem(localStorageKey, userId); |
| 13 | } |
| 14 | |
| 15 | return userId; |
| 16 | } |