fix: csrf on more public pages

This commit is contained in:
Morgan Vernay 2023-11-17 22:48:57 +02:00
parent 5b8c41c203
commit cd2d8bdb31
3 changed files with 4 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import type { GetServerSidePropsContext } from "next";
import { getCsrfToken, signIn } from "next-auth/react";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { setCsrfToken } from "pages/api/auth/csrf";
import type { CSSProperties } from "react";
import { useState } from "react";
import { FormProvider, useForm } from "react-hook-form";
@ -279,6 +280,7 @@ inferSSRProps<typeof _getServerSideProps> & WithNonceProps<{}>) {
// TODO: Once we understand how to retrieve prop types automatically from getServerSideProps, remove this temporary variable
const _getServerSideProps = async function getServerSideProps(context: GetServerSidePropsContext) {
setCsrfToken(context.res);
const { req, res, query } = context;
const session = await getServerSession({ req, res });

View File

@ -71,6 +71,7 @@ Logout.PageWrapper = PageWrapper;
export default Logout;
export async function getServerSideProps(context: GetServerSidePropsContext) {
setCsrfToken(context.res);
const ssr = await ssrInit(context);
// Deleting old cookie manually, remove this code after all existing cookies have expired
context.res.setHeader(

View File

@ -30,6 +30,7 @@ signin.PageWrapper = PageWrapper;
export default signin;
export async function getServerSideProps(context: GetServerSidePropsContext) {
setCsrfToken(context.res);
const { req, res } = context;
const session = await getServerSession({ req, res });