@@ -67,14 +67,23 @@ export const PayloadSessionProvider: React.FC<Props<CollectionSlug>> = <
67
67
*/
68
68
const fetchSession = useCallback (
69
69
async ( { signal } : { signal ?: AbortSignal } = { } ) => {
70
- // Fetch the session from the server
70
+ /**
71
+ * Fetch the session from the server
72
+ *
73
+ * @see https://payloadcms.com/docs/rest-api/overview#auth-operations
74
+ */
71
75
const response = await fetch ( `/api/${ userCollectionSlug } /me` , {
72
76
signal,
73
77
} ) ;
74
78
const result : {
75
79
user : DataFromCollectionSlug < TSlug > | null ;
76
80
exp : number ;
77
81
collection ?: CollectionSlug ;
82
+ /**
83
+ * @deprecated Use user._strategy instead
84
+ *
85
+ * @see https://github.com/payloadcms/payload/pull/11701
86
+ */
78
87
strategy ?: string ;
79
88
} = await response . json ( ) ;
80
89
@@ -91,7 +100,7 @@ export const PayloadSessionProvider: React.FC<Props<CollectionSlug>> = <
91
100
user : result . user ,
92
101
expires : new Date ( result . exp * 1000 ) . toISOString ( ) ,
93
102
collection : result . collection ,
94
- strategy : result . strategy ,
103
+ strategy : result . user . _strategy ?? result . strategy , // Extract the strategy from user._strategy or for legacy support directly from the result
95
104
} ;
96
105
setLocalSession ( localSession ) ;
97
106
@@ -121,12 +130,23 @@ export const PayloadSessionProvider: React.FC<Props<CollectionSlug>> = <
121
130
* Function to refresh the session
122
131
*/
123
132
const refresh = async ( ) => {
124
- // Refresh the session on the server
133
+ /**
134
+ * Refresh the session on the server
135
+ *
136
+ * @see https://payloadcms.com/docs/rest-api/overview#auth-operations
137
+ */
125
138
const response = await fetch ( `/api/${ userCollectionSlug } /refresh-token` , {
126
139
method : "POST" ,
127
140
} ) ;
128
- const result : { user : DataFromCollectionSlug < TSlug > | null ; exp : number } =
129
- await response . json ( ) ;
141
+ const result : {
142
+ user : DataFromCollectionSlug < TSlug > | null ;
143
+ exp : number /**
144
+ * @deprecated Use user._strategy instead
145
+ *
146
+ * @see https://github.com/payloadcms/payload/pull/11701
147
+ */ ;
148
+ strategy ?: string ;
149
+ } = await response . json ( ) ;
130
150
131
151
// If the response is not ok or the user is not present, return null
132
152
if ( ! response . ok || ! result . user ) {
@@ -137,6 +157,8 @@ export const PayloadSessionProvider: React.FC<Props<CollectionSlug>> = <
137
157
const localSession = {
138
158
user : result . user ,
139
159
expires : new Date ( result . exp * 1000 ) . toISOString ( ) ,
160
+ collection : result . user . collection ?? userCollectionSlug ,
161
+ strategy : result . user . _strategy ?? result . strategy , // Extract the strategy from user._strategy or for legacy support directly from the result
140
162
} ;
141
163
setLocalSession ( localSession ) ;
142
164
0 commit comments