Files
klz-cables.com/.pnpm-store/v10/files/50/6f0678dd5b4d0dc0c0b4ae613dd135bb8296a18cbeef8548ab52fdca8a32a6ae95ea6295e5ffb599974abdb9bc46107fe7d289a691682519f893ecf6459f8d
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

1 line
5.1 KiB
Plaintext

{"version":3,"sources":["../../../src/auth/operations/logout.ts"],"sourcesContent":["import { status as httpStatus } from 'http-status'\n\nimport type { Collection } from '../../collections/config/types.js'\nimport type { PayloadRequest } from '../../types/index.js'\n\nimport { APIError } from '../../errors/index.js'\nimport { appendNonTrashedFilter } from '../../utilities/appendNonTrashedFilter.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\n\nexport type Arguments = {\n allSessions?: boolean\n collection: Collection\n req: PayloadRequest\n}\n\nexport const logoutOperation = async (incomingArgs: Arguments): Promise<boolean> => {\n let args = incomingArgs\n const {\n allSessions,\n collection: { config: collectionConfig },\n req: { user },\n req,\n } = incomingArgs\n\n if (!user) {\n throw new APIError('No User', httpStatus.BAD_REQUEST)\n }\n if (user.collection !== collectionConfig.slug) {\n throw new APIError('Incorrect collection', httpStatus.FORBIDDEN)\n }\n\n const shouldCommit = await initTransaction(req)\n\n try {\n if (collectionConfig.hooks?.afterLogout?.length) {\n for (const hook of collectionConfig.hooks.afterLogout) {\n args =\n (await hook({\n collection: args.collection?.config,\n context: req.context,\n req,\n })) || args\n }\n }\n\n if (collectionConfig.auth.disableLocalStrategy !== true && collectionConfig.auth.useSessions) {\n const where = appendNonTrashedFilter({\n enableTrash: Boolean(collectionConfig.trash),\n trash: false,\n where: {\n id: {\n equals: user.id,\n },\n },\n })\n\n const userWithSessions = await req.payload.db.findOne<{\n id: number | string\n sessions: { id: string }[]\n }>({\n collection: collectionConfig.slug,\n req,\n where,\n })\n\n if (!userWithSessions) {\n throw new APIError('No User', httpStatus.BAD_REQUEST)\n }\n\n if (allSessions) {\n userWithSessions.sessions = []\n } else {\n const sessionsAfterLogout = (userWithSessions?.sessions || []).filter(\n (s) => s.id !== req?.user?._sid,\n )\n\n userWithSessions.sessions = sessionsAfterLogout\n }\n\n // Prevent updatedAt from being updated when only removing a session\n ;(userWithSessions as any).updatedAt = null\n\n await req.payload.db.updateOne({\n id: user.id,\n collection: collectionConfig.slug,\n data: userWithSessions,\n req,\n returning: false,\n })\n }\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return true\n } catch (error: unknown) {\n await killTransaction(req)\n throw error\n }\n}\n"],"names":["status","httpStatus","APIError","appendNonTrashedFilter","commitTransaction","initTransaction","killTransaction","logoutOperation","incomingArgs","args","allSessions","collection","config","collectionConfig","req","user","BAD_REQUEST","slug","FORBIDDEN","shouldCommit","hooks","afterLogout","length","hook","context","auth","disableLocalStrategy","useSessions","where","enableTrash","Boolean","trash","id","equals","userWithSessions","payload","db","findOne","sessions","sessionsAfterLogout","filter","s","_sid","updatedAt","updateOne","data","returning","error"],"mappings":"AAAA,SAASA,UAAUC,UAAU,QAAQ,cAAa;AAKlD,SAASC,QAAQ,QAAQ,wBAAuB;AAChD,SAASC,sBAAsB,QAAQ,4CAA2C;AAClF,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AAQpE,OAAO,MAAMC,kBAAkB,OAAOC;IACpC,IAAIC,OAAOD;IACX,MAAM,EACJE,WAAW,EACXC,YAAY,EAAEC,QAAQC,g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