File tree Expand file tree Collapse file tree 3 files changed +5
-12
lines changed
packages/payload-authjs/src/payload/collection Expand file tree Collapse file tree 3 files changed +5
-12
lines changed Original file line number Diff line number Diff line change @@ -6,23 +6,18 @@ import { getAllVirtualFields } from "../../utils/getAllVirtualFields";
66import { 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 */
1414export 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
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ import { getUserAttributes } from "../../utils/getUserAttributes";
1414export 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments