@payloadcms/next 3.55.0-canary.6 → 3.55.0-canary.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/refresh.js +8 -8
- package/dist/auth/refresh.js.map +1 -1
- package/dist/prod/styles.css +1 -1
- package/dist/views/CollectionFolders/buildView.d.ts.map +1 -1
- package/dist/views/CollectionFolders/buildView.js +1 -1
- package/dist/views/CollectionFolders/buildView.js.map +1 -1
- package/package.json +6 -6
package/dist/auth/refresh.js
CHANGED
|
@@ -18,6 +18,13 @@ export async function refresh({
|
|
|
18
18
|
if (!result.user) {
|
|
19
19
|
throw new Error('Cannot refresh token: user not authenticated');
|
|
20
20
|
}
|
|
21
|
+
const existingCookie = await getExistingAuthToken(payload.config.cookiePrefix);
|
|
22
|
+
if (!existingCookie) {
|
|
23
|
+
return {
|
|
24
|
+
message: 'No valid token found to refresh',
|
|
25
|
+
success: false
|
|
26
|
+
};
|
|
27
|
+
}
|
|
21
28
|
const collection = result.user.collection;
|
|
22
29
|
const collectionConfig = payload.collections[collection];
|
|
23
30
|
if (!collectionConfig?.config.auth) {
|
|
@@ -36,17 +43,10 @@ export async function refresh({
|
|
|
36
43
|
success: false
|
|
37
44
|
};
|
|
38
45
|
}
|
|
39
|
-
const existingCookie = await getExistingAuthToken(payload.config.cookiePrefix);
|
|
40
|
-
if (!existingCookie) {
|
|
41
|
-
return {
|
|
42
|
-
message: 'No valid token found to refresh',
|
|
43
|
-
success: false
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
46
|
await setPayloadAuthCookie({
|
|
47
47
|
authConfig: collectionConfig.config.auth,
|
|
48
48
|
cookiePrefix: payload.config.cookiePrefix,
|
|
49
|
-
token:
|
|
49
|
+
token: refreshResult.refreshedToken
|
|
50
50
|
});
|
|
51
51
|
return {
|
|
52
52
|
message: 'Token refreshed successfully',
|
package/dist/auth/refresh.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refresh.js","names":["headers","nextHeaders","createLocalReq","getPayload","refreshOperation","getExistingAuthToken","setPayloadAuthCookie","refresh","config","payload","cron","result","auth","user","Error","
|
|
1
|
+
{"version":3,"file":"refresh.js","names":["headers","nextHeaders","createLocalReq","getPayload","refreshOperation","getExistingAuthToken","setPayloadAuthCookie","refresh","config","payload","cron","result","auth","user","Error","existingCookie","cookiePrefix","message","success","collection","collectionConfig","collections","req","refreshResult","authConfig","token","refreshedToken"],"sources":["../../src/auth/refresh.ts"],"sourcesContent":["'use server'\n\nimport type { CollectionSlug } from 'payload'\n\nimport { headers as nextHeaders } from 'next/headers.js'\nimport { createLocalReq, getPayload, refreshOperation } from 'payload'\n\nimport { getExistingAuthToken } from '../utilities/getExistingAuthToken.js'\nimport { setPayloadAuthCookie } from '../utilities/setPayloadAuthCookie.js'\n\nexport async function refresh({ config }: { config: any }) {\n const payload = await getPayload({ config, cron: true })\n const headers = await nextHeaders()\n const result = await payload.auth({ headers })\n\n if (!result.user) {\n throw new Error('Cannot refresh token: user not authenticated')\n }\n\n const existingCookie = await getExistingAuthToken(payload.config.cookiePrefix)\n if (!existingCookie) {\n return { message: 'No valid token found to refresh', success: false }\n }\n\n const collection: CollectionSlug | undefined = result.user.collection\n const collectionConfig = payload.collections[collection]\n\n if (!collectionConfig?.config.auth) {\n throw new Error(`No auth config found for collection: ${collection}`)\n }\n\n const req = await createLocalReq({ user: result.user }, payload)\n\n const refreshResult = await refreshOperation({\n collection: collectionConfig,\n req,\n })\n\n if (!refreshResult) {\n return { message: 'Token refresh failed', success: false }\n }\n\n await setPayloadAuthCookie({\n authConfig: collectionConfig.config.auth,\n cookiePrefix: payload.config.cookiePrefix,\n token: refreshResult.refreshedToken,\n })\n\n return { message: 'Token refreshed successfully', success: true }\n}\n"],"mappings":"AAAA;;AAIA,SAASA,OAAA,IAAWC,WAAW,QAAQ;AACvC,SAASC,cAAc,EAAEC,UAAU,EAAEC,gBAAgB,QAAQ;AAE7D,SAASC,oBA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