Files
klz-cables.com/.pnpm-store/v10/files/48/a267f5d965fca2a26f492f96869d0c63f4a2d64f1b2d87ab80083cd59f46cd90feba81c9e6c3e5134ceae3e95a324715c013ff543e1dfa91b1337f3a592b19
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

56 lines
1.6 KiB
Plaintext

'use server';
import { headers as nextHeaders } from 'next/headers.js';
import { createLocalReq, getPayload, refreshOperation } from 'payload';
import { getExistingAuthToken } from '../utilities/getExistingAuthToken.js';
import { setPayloadAuthCookie } from '../utilities/setPayloadAuthCookie.js';
export async function refresh({
config
}) {
const payload = await getPayload({
config,
cron: true
});
const headers = await nextHeaders();
const result = await payload.auth({
headers
});
if (!result.user) {
throw new Error('Cannot refresh token: user not authenticated');
}
const existingCookie = await getExistingAuthToken(payload.config.cookiePrefix);
if (!existingCookie) {
return {
message: 'No valid token found to refresh',
success: false
};
}
const collection = result.user.collection;
const collectionConfig = payload.collections[collection];
if (!collectionConfig?.config.auth) {
throw new Error(`No auth config found for collection: ${collection}`);
}
const req = await createLocalReq({
user: result.user
}, payload);
const refreshResult = await refreshOperation({
collection: collectionConfig,
req
});
if (!refreshResult) {
return {
message: 'Token refresh failed',
success: false
};
}
await setPayloadAuthCookie({
authConfig: collectionConfig.config.auth,
cookiePrefix: payload.config.cookiePrefix,
token: refreshResult.refreshedToken
});
return {
message: 'Token refreshed successfully',
success: true
};
}
//# sourceMappingURL=refresh.js.map