From e39866e50e1da8e5b2470efbd5bd9299ff279c72 Mon Sep 17 00:00:00 2001 From: quentingrchr Date: Thu, 20 Jun 2024 11:41:57 +0200 Subject: [PATCH 1/2] fix cookie set --- src/components/digests/DigestCreateInput.tsx | 21 +++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/components/digests/DigestCreateInput.tsx b/src/components/digests/DigestCreateInput.tsx index e95b110..d4f58c9 100644 --- a/src/components/digests/DigestCreateInput.tsx +++ b/src/components/digests/DigestCreateInput.tsx @@ -1,22 +1,22 @@ 'use client'; +import { COOKIES, routes } from '@/core/constants'; import useCustomToast from '@/hooks/useCustomToast'; import useTransitionRefresh from '@/hooks/useTransitionRefresh'; import api from '@/lib/api'; import { ApiDigestResponseSuccess } from '@/pages/api/teams/[teamId]/digests'; +import { TeamDigestsResult } from '@/services/database/digest'; +import { Team } from '@prisma/client'; import { AxiosError, AxiosResponse } from 'axios'; +import clsx from 'clsx'; +import { useRouter } from 'next/navigation'; import { FormEvent, useEffect } from 'react'; +import { useCookies } from 'react-cookie'; +import { useForm } from 'react-hook-form'; import { useMutation } from 'react-query'; -import { COOKIES, routes } from '@/core/constants'; -import { useRouter } from 'next/navigation'; -import clsx from 'clsx'; import Button from '../Button'; import { Input, Select } from '../Input'; -import { Team } from '@prisma/client'; import { formatTemplateTitle } from './templates/TemplateItem'; -import { useForm } from 'react-hook-form'; -import { useCookies } from 'react-cookie'; -import { TeamDigestsResult } from '@/services/database/digest'; type Props = { team: Team; @@ -30,7 +30,7 @@ export const DigestCreateInput = ({ templates, }: Props) => { const router = useRouter(); - const [_, setCookie] = useCookies([COOKIES.DEFAULT_TEAM]); + const [_, setCookie, removeCookie] = useCookies([COOKIES.DEFAULT_TEAM]); const { successToast, errorToast } = useCustomToast(); const { isRefreshing, refresh } = useTransitionRefresh(); const methods = useForm<{ title: string; templateId?: string }>({ @@ -83,7 +83,10 @@ export const DigestCreateInput = ({ useEffect(() => { if (!team.slug) return; - setCookie(COOKIES.DEFAULT_TEAM, team.slug); + setCookie(COOKIES.DEFAULT_TEAM, team.slug, { + sameSite: 'strict', + path: '/', + }); }); return ( From 8993a47aca57f5ba2af589d47b4b68babbc22e7e Mon Sep 17 00:00:00 2001 From: quentingrchr Date: Thu, 20 Jun 2024 11:44:17 +0200 Subject: [PATCH 2/2] remove unused var --- src/components/digests/DigestCreateInput.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/digests/DigestCreateInput.tsx b/src/components/digests/DigestCreateInput.tsx index d4f58c9..2975d6d 100644 --- a/src/components/digests/DigestCreateInput.tsx +++ b/src/components/digests/DigestCreateInput.tsx @@ -30,7 +30,7 @@ export const DigestCreateInput = ({ templates, }: Props) => { const router = useRouter(); - const [_, setCookie, removeCookie] = useCookies([COOKIES.DEFAULT_TEAM]); + const [_, setCookie] = useCookies([COOKIES.DEFAULT_TEAM]); const { successToast, errorToast } = useCustomToast(); const { isRefreshing, refresh } = useTransitionRefresh(); const methods = useForm<{ title: string; templateId?: string }>({