()
| 1 | export function getUserId(): string { |
| 2 | if (typeof window === 'undefined') return 'user_local' |
| 3 | try { |
| 4 | const KEY = 'nfca_user_id' |
| 5 | const existing = window.localStorage.getItem(KEY) |
| 6 | if (existing && existing.trim()) return existing |
| 7 | const generated = `user_${Date.now().toString(36)}_${Math.random() |
| 8 | .toString(36) |
| 9 | .slice(2, 10)}` |
| 10 | window.localStorage.setItem(KEY, generated) |
| 11 | return generated |
| 12 | } catch { |
| 13 | return 'user_local' |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | export function ensureGlobalUserId(): string { |
| 18 | const id = getUserId() |
no test coverage detected