Skip to content

Commit

Permalink
add hook for session cookie (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
SalmanAsh authored Aug 21, 2024
1 parent 0758d09 commit a93eb27
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/app/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AppDispatch>()
export const useAppSelector = useSelector.withTypes<RootState>()

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
}

0 comments on commit a93eb27

Please sign in to comment.