Skip to content

Commit

Permalink
feat: memoize profile guard
Browse files Browse the repository at this point in the history
  • Loading branch information
dominik-stumpf committed Aug 9, 2024
1 parent 60020c3 commit 12ae70c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/app/(marketing)/profile/_components/ProfileOwnerGuard.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
"use client"

import { useUserPublic } from "@/hooks/useUserPublic"
import { PropsWithChildren } from "react"
import { PropsWithChildren, useMemo } from "react"
import { useProfile } from "../_hooks/useProfile"

export const ProfileOwnerGuard = ({ children }: PropsWithChildren) => {
const { data: profile } = useProfile()
const { id: publicUserId } = useUserPublic()
const isProfileOwner = !!profile?.userId && publicUserId === profile.userId

const isProfileOwner = useMemo(
() => !!profile?.userId && publicUserId === profile.userId,
[publicUserId]
)
if (!isProfileOwner) return
return children
}
2 changes: 2 additions & 0 deletions src/hooks/useSetKeyPair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const useSetKeyPair = (submitOptions?: UseSubmitOptions) => {
const recaptcha = useAtomValue(recaptchaAtom)

const setSubmitResponse = useSubmit(
// @ts-ignore
async ({
signProps,
}: {
Expand Down Expand Up @@ -175,6 +176,7 @@ const useSetKeyPair = (submitOptions?: UseSubmitOptions) => {
return { keyPair: generatedKeys, user: userProfile }
},

// @ts-ignore
{
...submitOptions,
onError: (error) => {
Expand Down

0 comments on commit 12ae70c

Please sign in to comment.