From 273937288a7d2b48c66b0c4476c0cf08a45bea01 Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Tue, 20 Aug 2024 12:59:25 +0000 Subject: [PATCH] add hook for session cookie --- src/app/hooks.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/app/hooks.ts b/src/app/hooks.ts index 172beff..edad679 100644 --- a/src/app/hooks.ts +++ b/src/app/hooks.ts @@ -7,7 +7,20 @@ import { useDispatch, useSelector } from "react-redux" import type { AppDispatch, RootState } from "./store" +import Cookies from "js-cookie" // Use throughout your app instead of plain `useDispatch` and `useSelector` export const useAppDispatch = useDispatch.withTypes() export const useAppSelector = useSelector.withTypes() + +export interface SessionMetadata { + contributor_id: number +} + +export function useSessionMetadata(): SessionMetadata | undefined { + const sessionMetadata = Cookies.get("session_metadata") + + return sessionMetadata + ? (JSON.parse(sessionMetadata) as SessionMetadata) + : undefined +}