Check if client for session id hook
This commit is contained in:
@@ -3,8 +3,13 @@ import { v4 as uuidv4 } from "uuid"
|
||||
|
||||
const storageKey = "sessionId"
|
||||
|
||||
export function useSessionId(): string {
|
||||
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 = uuidv4()
|
||||
|
||||
Reference in New Issue
Block a user