mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 16:23:06 +10:00
feat: cache getServerComponentSession calls (#644)
This commit is contained in:
@ -1,3 +1,5 @@
|
|||||||
|
import { cache } from 'react';
|
||||||
|
|
||||||
import { GetServerSidePropsContext, NextApiRequest, NextApiResponse } from 'next';
|
import { GetServerSidePropsContext, NextApiRequest, NextApiResponse } from 'next';
|
||||||
|
|
||||||
import { getServerSession as getNextAuthServerSession } from 'next-auth';
|
import { getServerSession as getNextAuthServerSession } from 'next-auth';
|
||||||
@ -27,7 +29,7 @@ export const getServerSession = async ({ req, res }: GetServerSessionOptions) =>
|
|||||||
return { user, session };
|
return { user, session };
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getServerComponentSession = async () => {
|
export const getServerComponentSession = cache(async () => {
|
||||||
const session = await getNextAuthServerSession(NEXT_AUTH_OPTIONS);
|
const session = await getNextAuthServerSession(NEXT_AUTH_OPTIONS);
|
||||||
|
|
||||||
if (!session || !session.user?.email) {
|
if (!session || !session.user?.email) {
|
||||||
@ -41,9 +43,9 @@ export const getServerComponentSession = async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return { user, session };
|
return { user, session };
|
||||||
};
|
});
|
||||||
|
|
||||||
export const getRequiredServerComponentSession = async () => {
|
export const getRequiredServerComponentSession = cache(async () => {
|
||||||
const { user, session } = await getServerComponentSession();
|
const { user, session } = await getServerComponentSession();
|
||||||
|
|
||||||
if (!user || !session) {
|
if (!user || !session) {
|
||||||
@ -51,4 +53,4 @@ export const getRequiredServerComponentSession = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return { user, session };
|
return { user, session };
|
||||||
};
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user