fix: rename sessionId storage name to avoid conflict with current web * fix: rename sessionId storage name to avoid conflict with current web
23 lines
546 B
TypeScript
23 lines
546 B
TypeScript
import { nanoid } from "nanoid"
|
|
import { useMemo } from "react"
|
|
|
|
const storageKey = "web_sessionId"
|
|
|
|
export function useSessionId(): string | null {
|
|
const sessionId = useMemo(() => {
|
|
if (typeof window === "undefined") {
|
|
// Return null if running on the server
|
|
return null
|
|
}
|
|
|
|
let currentSessionId = sessionStorage.getItem(storageKey)
|
|
if (!currentSessionId) {
|
|
currentSessionId = nanoid()
|
|
sessionStorage.setItem(storageKey, currentSessionId)
|
|
}
|
|
return currentSessionId
|
|
}, [])
|
|
|
|
return sessionId
|
|
}
|