Skip to content

Commit 382bac5

Browse files
committed
fix: Register me hook always to provider expires timestamp (#12)
1 parent 12a2476 commit 382bac5

File tree

3 files changed

+5
-12
lines changed

3 files changed

+5
-12
lines changed

packages/payload-authjs/src/payload/collection/hooks/me.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,18 @@ import { getAllVirtualFields } from "../../utils/getAllVirtualFields";
66
import { getUserAttributes } from "../../utils/getUserAttributes";
77

88
/**
9-
* Add me hook to override the me endpoint to include virtual fields
9+
* Add me hook to override the me endpoint to include 'exp' and virtual fields
1010
*
1111
* @see https://payloadcms.com/docs/hooks/collections#me
1212
* @see https://github.com/payloadcms/payload/blob/main/packages/payload/src/auth/operations/me.ts
1313
*/
1414
export const meHook: (
1515
collection: CollectionConfig,
1616
pluginOptions: AuthjsPluginConfig,
17-
) => CollectionMeHook | undefined = (collection, pluginOptions) => {
17+
) => CollectionMeHook = (collection, pluginOptions) => {
1818
// Get all virtual fields
1919
const virtualFields = getAllVirtualFields(collection.fields);
2020

21-
// If no virtual fields exist, no need to override the me endpoint
22-
if (virtualFields.length === 0) {
23-
return undefined;
24-
}
25-
2621
// Return the me hook
2722
return async ({ args: { req }, user }) => {
2823
// Get session from authjs

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { getUserAttributes } from "../../utils/getUserAttributes";
1414
export const refreshHook: (
1515
collection: CollectionConfig,
1616
pluginOptions: AuthjsPluginConfig,
17-
) => CollectionRefreshHook | undefined = (collection, pluginOptions) => {
17+
) => CollectionRefreshHook = (collection, pluginOptions) => {
1818
// Get all virtual fields
1919
const virtualFields = getAllVirtualFields(collection.fields);
2020

packages/payload-authjs/src/payload/collection/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,10 @@ export const generateUsersCollection = (
9393
};
9494

9595
// Add hooks to users collection
96-
const _meHook = meHook(collection, pluginOptions);
97-
const _refreshHook = refreshHook(collection, pluginOptions);
9896
collection.hooks = {
9997
...collection.hooks,
100-
me: [...(collection.hooks?.me || []), ...(_meHook ? [_meHook] : [])],
101-
refresh: [...(collection.hooks?.refresh || []), ...(_refreshHook ? [_refreshHook] : [])],
98+
me: [...(collection.hooks?.me || []), meHook(collection, pluginOptions)],
99+
refresh: [...(collection.hooks?.refresh || []), refreshHook(collection, pluginOptions)],
102100
};
103101

104102
// Add custom endpoints to users collection

0 commit comments

Comments
 (0)