Skip to content

Commit

Permalink
fix: use session metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Oct 23, 2024
1 parent 4283964 commit 45d34fb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
16 changes: 0 additions & 16 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,6 @@
{
"fixStyle": "inline-type-imports"
}
],
"@typescript-eslint/no-restricted-imports": [
2,
{
"paths": [
{
"name": "react-redux",
"importNames": [
"useSelector",
"useStore",
"useDispatch"
],
"message": "Please use pre-typed versions from `src/app/hooks.ts` instead."
}
]
}
]
},
"overrides": [
Expand Down
11 changes: 8 additions & 3 deletions src/hooks/auth.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import Cookies from "js-cookie"
import { useEffect, type ReactNode } from "react"
import { createSearchParams, useLocation, useNavigate } from "react-router-dom"
import { useSelector } from "react-redux"

import { type AuthFactor, type User } from "../api"
import { SESSION_METADATA_COOKIE_NAME } from "../env"
import { selectIsLoggedIn } from "../slices/session"

export interface SessionMetadata {
user_id: User["id"]
Expand All @@ -12,9 +15,11 @@ export interface SessionMetadata {
}

export function useSessionMetadata(): SessionMetadata | undefined {
const sessionMetadata = Cookies.get("session_metadata")

return sessionMetadata ? JSON.parse(sessionMetadata) : undefined
return useSelector(selectIsLoggedIn)
? (JSON.parse(
Cookies.get(SESSION_METADATA_COOKIE_NAME)!,
) as SessionMetadata)
: undefined
}

export type UseSessionChildrenFunction<Required extends boolean> = (
Expand Down

0 comments on commit 45d34fb

Please sign in to comment.