Files
klz-cables.com/.pnpm-store/v10/files/75/5a74607024b007fed2d8ecb0b651919f46286452f5c5f428a048fcb96388aac7584b082ce942f44e1417cf09d419f3bc8645091b2cd1403e681c0794895c97
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

81 lines
2.5 KiB
Plaintext

import { decodeJwt } from 'jose';
export const meOperation = async (args)=>{
const { collection, currentToken, depth, draft, joins, populate, req, select } = args;
let result = {
user: null
};
if (req.user) {
const { pathname } = req;
const isGraphQL = pathname === `/api${req.payload.config.routes.graphQL}`;
const user = await req.payload.findByID({
id: req.user.id,
collection: collection.config.slug,
depth: isGraphQL ? 0 : depth ?? collection.config.auth.depth,
draft,
joins,
overrideAccess: false,
populate,
req,
select,
showHiddenFields: false
});
if (user) {
user.collection = collection.config.slug;
user._strategy = req.user._strategy;
}
if (req.user.collection !== collection.config.slug) {
return {
user: null
};
}
// /////////////////////////////////////
// me hook - Collection
// /////////////////////////////////////
for (const meHook of collection.config.hooks.me){
const hookResult = await meHook({
args,
user
});
if (hookResult) {
result.user = hookResult.user;
result.exp = hookResult.exp;
break;
}
}
result.collection = req.user.collection;
/** @deprecated
* use:
* ```ts
* user._strategy
* ```
*/ result.strategy = req.user._strategy;
if (!result.user) {
result.user = user;
if (currentToken) {
const decoded = decodeJwt(currentToken);
if (decoded) {
result.exp = decoded.exp;
}
if (!collection.config.auth.removeTokenFromResponses) {
result.token = currentToken;
}
}
}
}
// /////////////////////////////////////
// After Me - Collection
// /////////////////////////////////////
if (collection.config.hooks?.afterMe?.length) {
for (const hook of collection.config.hooks.afterMe){
result = await hook({
collection: collection?.config,
context: req.context,
req,
response: result
}) || result;
}
}
return result;
};
//# sourceMappingURL=me.js.map