Skip to content

Commit 25d4b8d

Browse files
committed
fix: Revalidate payload-session tag on logout and refresh
1 parent 27ee17b commit 25d4b8d

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

packages/payload-authjs/src/payload/collection/endpoints/logout.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { withPayload } from "../../../authjs/withPayload";
77
import { AUTHJS_STRATEGY_NAME } from "../../AuthjsAuthStrategy";
88
import type { AuthjsPluginConfig } from "../../plugin";
99
import { getRequestCollection } from "../../utils/getRequestCollection";
10+
import { revalidateTag } from "next/cache";
1011

1112
/**
1213
* Override the default logout endpoint to destroy the authjs session
@@ -67,6 +68,9 @@ export const logoutEndpoint: (pluginOptions: AuthjsPluginConfig) => Endpoint = p
6768
// If the user is authenticated using authjs, we need to destroy the authjs session cookie
6869
if (req.user?._strategy === AUTHJS_STRATEGY_NAME) {
6970
await destroyAuthjsSessionCookie(req, response, pluginOptions);
71+
72+
// Revalidate the cache for the payload session
73+
revalidateTag("payload-session");
7074
}
7175

7276
return response;

packages/payload-authjs/src/payload/collection/endpoints/refresh.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import NextAuth from "next-auth";
22
import type { Endpoint, PayloadRequest } from "payload";
33
import { generatePayloadCookie, headersWithCors, refreshOperation } from "payload";
44

5+
import { revalidateTag } from "next/cache";
56
import { withPayload } from "../../../authjs/withPayload";
67
import { AUTHJS_STRATEGY_NAME } from "../../AuthjsAuthStrategy";
78
import type { AuthjsPluginConfig } from "../../plugin";
@@ -64,6 +65,9 @@ export const refreshEndpoint: (pluginOptions: AuthjsPluginConfig) => Endpoint =
6465
// If the user is authenticated using authjs, we need to refresh the authjs session cookie
6566
if (result.user?._strategy === AUTHJS_STRATEGY_NAME) {
6667
await refreshAuthjsSessionCookie(req, response, pluginOptions);
68+
69+
// Revalidate the cache for the payload session
70+
revalidateTag("payload-session");
6771
}
6872

6973
return response;

0 commit comments

Comments
 (0)