@payloadcms/next 3.0.0-beta.22 → 3.0.0-beta.24
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/exports/utilities.d.ts +1 -1
- package/dist/exports/utilities.d.ts.map +1 -1
- package/dist/exports/utilities.js +1 -1
- package/dist/exports/utilities.js.map +1 -1
- package/dist/prod/styles.css +1 -1
- package/dist/routes/rest/buildFormState.d.ts.map +1 -1
- package/dist/routes/rest/buildFormState.js +1 -0
- package/dist/routes/rest/buildFormState.js.map +1 -1
- package/dist/utilities/initPage/handleAdminPage.d.ts +13 -0
- package/dist/utilities/initPage/handleAdminPage.d.ts.map +1 -0
- package/dist/utilities/initPage/handleAdminPage.js +35 -0
- package/dist/utilities/initPage/handleAdminPage.js.map +1 -0
- package/dist/utilities/initPage/handleAuthRedirect.d.ts +9 -0
- package/dist/utilities/initPage/handleAuthRedirect.d.ts.map +1 -0
- package/dist/utilities/initPage/handleAuthRedirect.js +26 -0
- package/dist/utilities/initPage/handleAuthRedirect.js.map +1 -0
- package/dist/utilities/initPage/index.d.ts +4 -0
- package/dist/utilities/initPage/index.d.ts.map +1 -0
- package/dist/utilities/initPage/index.js +89 -0
- package/dist/utilities/initPage/index.js.map +1 -0
- package/dist/utilities/initPage/shared.d.ts +4 -0
- package/dist/utilities/initPage/shared.d.ts.map +1 -0
- package/dist/utilities/initPage/shared.js +17 -0
- package/dist/utilities/initPage/shared.js.map +1 -0
- package/dist/utilities/initPage/types.d.ts +24 -0
- package/dist/utilities/initPage/types.d.ts.map +1 -0
- package/dist/utilities/initPage/types.js +3 -0
- package/dist/utilities/initPage/types.js.map +1 -0
- package/dist/views/NotFound/index.js +1 -1
- package/dist/views/NotFound/index.js.map +1 -1
- package/dist/views/ResetPassword/index.client.d.ts +7 -0
- package/dist/views/ResetPassword/index.client.d.ts.map +1 -0
- package/dist/views/ResetPassword/index.client.js +83 -0
- package/dist/views/ResetPassword/index.client.js.map +1 -0
- package/dist/views/ResetPassword/index.d.ts.map +1 -1
- package/dist/views/ResetPassword/index.js +6 -31
- package/dist/views/ResetPassword/index.js.map +1 -1
- package/dist/views/ResetPassword/index.scss +2 -12
- package/dist/views/Root/getViewFromConfig.d.ts +1 -1
- package/dist/views/Root/getViewFromConfig.d.ts.map +1 -1
- package/dist/views/Root/getViewFromConfig.js.map +1 -1
- package/dist/views/Root/index.js +1 -1
- package/dist/views/Root/index.js.map +1 -1
- package/package.json +6 -6
- package/dist/utilities/initPage.d.ts +0 -12
- package/dist/utilities/initPage.d.ts.map +0 -1
- package/dist/utilities/initPage.js +0 -113
- package/dist/utilities/initPage.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildFormState.d.ts","sourceRoot":"","sources":["../../../src/routes/rest/buildFormState.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA8B,sBAAsB,EAAc,MAAM,eAAe,CAAA;AAMnG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8CAA8C,CAAA;AAalF,eAAO,MAAM,iBAAiB,QAAS,sBAAsB,mBAQ5D,CAAA;AAED,eAAO,MAAM,cAAc,YAAmB;IAAE,GAAG,EAAE,sBAAsB,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"buildFormState.d.ts","sourceRoot":"","sources":["../../../src/routes/rest/buildFormState.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA8B,sBAAsB,EAAc,MAAM,eAAe,CAAA;AAMnG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8CAA8C,CAAA;AAalF,eAAO,MAAM,iBAAiB,QAAS,sBAAsB,mBAQ5D,CAAA;AAED,eAAO,MAAM,cAAc,YAAmB;IAAE,GAAG,EAAE,sBAAsB,CAAA;CAAE,sBAiN5E,CAAA"}
|
|
@@ -171,6 +171,7 @@ export const buildFormState = async ({ req })=>{
|
|
|
171
171
|
}
|
|
172
172
|
if (req.payload.collections[collectionSlug]?.config?.auth && !req.payload.collections[collectionSlug].config.auth.disableLocalStrategy) {
|
|
173
173
|
if (formState.password) result.password = formState.password;
|
|
174
|
+
if (formState['confirm-password']) result['confirm-password'] = formState['confirm-password'];
|
|
174
175
|
if (formState.email) result.email = formState.email;
|
|
175
176
|
}
|
|
176
177
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/routes/rest/buildFormState.ts"],"sourcesContent":["import type { BuildFormStateArgs } from '@payloadcms/ui/forms/buildStateFromSchema'\nimport type { DocumentPreferences, Field, PayloadRequestWithData, TypeWithID } from 'payload/types'\n\nimport { buildStateFromSchema } from '@payloadcms/ui/forms/buildStateFromSchema'\nimport { reduceFieldsToValues } from '@payloadcms/ui/utilities/reduceFieldsToValues'\nimport httpStatus from 'http-status'\n\nimport type { FieldSchemaMap } from '../../utilities/buildFieldSchemaMap/types.js'\n\nimport { buildFieldSchemaMap } from '../../utilities/buildFieldSchemaMap/index.js'\nimport { headersWithCors } from '../../utilities/headersWithCors.js'\nimport { routeError } from './routeError.js'\n\nlet cached = global._payload_fieldSchemaMap\n\nif (!cached) {\n // eslint-disable-next-line no-multi-assign\n cached = global._payload_fieldSchemaMap = null\n}\n\nexport const getFieldSchemaMap = (req: PayloadRequestWithData): FieldSchemaMap => {\n if (cached && process.env.NODE_ENV !== 'development') {\n return cached\n }\n\n cached = buildFieldSchemaMap(req)\n\n return cached\n}\n\nexport const buildFormState = async ({ req }: { req: PayloadRequestWithData }) => {\n const headers = headersWithCors({\n headers: new Headers(),\n req,\n })\n\n try {\n const reqData: BuildFormStateArgs = req.data as BuildFormStateArgs\n const { collectionSlug, formState, globalSlug, locale, operation, schemaPath } = reqData\n\n const incomingUserSlug = req.user?.collection\n const adminUserSlug = req.payload.config.admin.user\n\n // If we have a user slug, test it against the functions\n if (incomingUserSlug) {\n const adminAccessFunction = req.payload.collections[incomingUserSlug].config.access?.admin\n\n // Run the admin access function from the config if it exists\n if (adminAccessFunction) {\n const canAccessAdmin = await adminAccessFunction({ req })\n\n if (!canAccessAdmin) {\n return Response.json(null, {\n headers,\n status: httpStatus.UNAUTHORIZED,\n })\n }\n // Match the user collection to the global admin config\n } else if (adminUserSlug !== incomingUserSlug) {\n return Response.json(null, {\n headers,\n status: httpStatus.UNAUTHORIZED,\n })\n }\n } else {\n const hasUsers = await req.payload.find({\n collection: adminUserSlug,\n depth: 0,\n limit: 1,\n pagination: false,\n })\n // If there are users, we should not allow access because of /create-first-user\n if (hasUsers.docs.length) {\n return Response.json(null, {\n headers,\n status: httpStatus.UNAUTHORIZED,\n })\n }\n }\n\n const fieldSchemaMap = getFieldSchemaMap(req)\n\n const id = collectionSlug ? reqData.id : undefined\n const schemaPathSegments = schemaPath.split('.')\n\n let fieldSchema: Field[]\n\n if (schemaPathSegments.length === 1) {\n if (req.payload.collections[schemaPath]) {\n fieldSchema = req.payload.collections[schemaPath].config.fields\n } else {\n fieldSchema = req.payload.config.globals.find(\n (global) => global.slug === schemaPath,\n )?.fields\n }\n } else if (fieldSchemaMap.has(schemaPath)) {\n fieldSchema = fieldSchemaMap.get(schemaPath)\n }\n\n if (!fieldSchema) {\n return Response.json(\n {\n message: 'Could not find field schema for given path',\n },\n {\n headers,\n status: httpStatus.BAD_REQUEST,\n },\n )\n }\n\n let docPreferences = reqData.docPreferences\n let data = reqData.data\n\n const promises: {\n data?: Promise<void>\n preferences?: Promise<void>\n } = {}\n\n // If the request does not include doc preferences,\n // we should fetch them. This is useful for DocumentInfoProvider\n // as it reduces the amount of client-side fetches necessary\n // when we fetch data for the Edit view\n if (!docPreferences) {\n let preferencesKey\n\n if (collectionSlug && id) {\n preferencesKey = `collection-${collectionSlug}-${id}`\n }\n\n if (globalSlug) {\n preferencesKey = `global-${globalSlug}`\n }\n\n if (preferencesKey) {\n const fetchPreferences = async () => {\n const preferencesResult = (await req.payload.find({\n collection: 'payload-preferences',\n depth: 0,\n limit: 1,\n where: {\n key: {\n equals: preferencesKey,\n },\n },\n })) as unknown as { docs: { value: DocumentPreferences }[] }\n\n if (preferencesResult?.docs?.[0]?.value) docPreferences = preferencesResult.docs[0].value\n }\n\n promises.preferences = fetchPreferences()\n }\n }\n\n // If there is a form state,\n // then we can deduce data from that form state\n if (formState) data = reduceFieldsToValues(formState, true)\n\n // If we do not have data at this point,\n // we can fetch it. This is useful for DocumentInfoProvider\n // to reduce the amount of fetches required\n if (!data) {\n const fetchData = async () => {\n let resolvedData: TypeWithID\n\n if (collectionSlug && id) {\n resolvedData = await req.payload.findByID({\n id,\n collection: collectionSlug,\n depth: 0,\n draft: true,\n fallbackLocale: null,\n locale,\n overrideAccess: false,\n user: req.user,\n })\n }\n\n if (globalSlug && schemaPath === globalSlug) {\n resolvedData = await req.payload.findGlobal({\n slug: globalSlug,\n depth: 0,\n draft: true,\n fallbackLocale: null,\n locale,\n overrideAccess: false,\n user: req.user,\n })\n }\n\n data = resolvedData\n }\n\n promises.data = fetchData()\n }\n\n if (Object.keys(promises).length > 0) {\n await Promise.all(Object.values(promises))\n }\n\n const result = await buildStateFromSchema({\n id,\n data,\n fieldSchema,\n operation,\n preferences: docPreferences || { fields: {} },\n req,\n })\n\n // Maintain form state of auth / upload fields\n if (collectionSlug && formState) {\n if (req.payload.collections[collectionSlug]?.config?.upload && formState.file) {\n result.file = formState.file\n }\n\n if (\n req.payload.collections[collectionSlug]?.config?.auth &&\n !req.payload.collections[collectionSlug].config.auth.disableLocalStrategy\n ) {\n if (formState.password) result.password = formState.password\n if (formState.email) result.email = formState.email\n }\n }\n\n return Response.json(result, {\n headers,\n status: httpStatus.OK,\n })\n } catch (err) {\n req.payload.logger.error({ err, msg: `There was an error building form state` })\n\n return routeError({\n config: req.payload.config,\n err,\n req,\n })\n }\n}\n"],"names":["buildStateFromSchema","reduceFieldsToValues","httpStatus","buildFieldSchemaMap","headersWithCors","routeError","cached","global","_payload_fieldSchemaMap","getFieldSchemaMap","req","process","env","NODE_ENV","buildFormState","headers","Headers","reqData","data","collectionSlug","formState","globalSlug","locale","operation","schemaPath","incomingUserSlug","user","collection","adminUserSlug","payload","config","admin","adminAccessFunction","collections","access","canAccessAdmin","Response","json","status","UNAUTHORIZED","hasUsers","find","depth","limit","pagination","docs","length","fieldSchemaMap","id","undefined","schemaPathSegments","split","fieldSchema","fields","globals","slug","has","get","message","BAD_REQUEST","docPreferences","promises","preferencesKey","fetchPreferences","preferencesResult","where","key","equals","value","preferences","fetchData","resolvedData","findByID","draft","fallbackLocale","overrideAccess","findGlobal","Object","keys","Promise","all","values","result","upload","file","auth","disableLocalStrategy","password","email","OK","err","logger","error","msg"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,SAASA,oBAAoB,QAAQ,4CAA2C;AAChF,SAASC,oBAAoB,QAAQ,gDAA+C;AACpF,OAAOC,gBAAgB,cAAa;AAIpC,SAASC,mBAAmB,QAAQ,+CAA8C;AAClF,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,UAAU,QAAQ,kBAAiB;AAE5C,IAAIC,SAASC,OAAOC,uBAAuB;AAE3C,IAAI,CAACF,QAAQ;IACX,2CAA2C;IAC3CA,SAASC,OAAOC,uBAAuB,GAAG;AAC5C;AAEA,OAAO,MAAMC,oBAAoB,CAACC;IAChC,IAAIJ,UAAUK,QAAQC,GAAG,CAACC,QAAQ,KAAK,eAAe;QACpD,OAAOP;IACT;IAEAA,SAASH,oBAAoBO;IAE7B,OAAOJ;AACT,EAAC;AAED,OAAO,MAAMQ,iBAAiB,OAAO,EAAEJ,GAAG,EAAmC;IAC3E,MAAMK,UAAUX,gBAAgB;QAC9BW,SAAS,IAAIC;QACbN;IACF;IAEA,IAAI;QACF,MAAMO,UAA8BP,IAAIQ,IAAI;QA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W,CAACd,eAAe,CAACW,MAAM,CAACuD,IAAI,CAACC,oBAAoB,EACzE;gBACA,IAAIlE,UAAUmE,QAAQ,EAAEL,OAAOK,QAAQ,GAAGnE,UAAUmE,QAAQ;gBAC5D,IAAInE,UAAUoE,KAAK,EAAEN,OAAOM,KAAK,GAAGpE,UAAUoE,KAAK;YACrD;QACF;QAEA,OAAOpD,SAASC,IAAI,CAAC6C,QAAQ;YAC3BnE;YACAuB,QAAQpC,WAAWuF,EAAE;QACvB;IACF,EAAE,OAAOC,KAAK;QACZhF,IAAImB,OAAO,CAAC8D,MAAM,CAACC,KAAK,CAAC;YAAEF;YAAKG,KAAK,CAAC,sCAAsC,CAAC;QAAC;QAE9E,OAAOxF,WAAW;YAChByB,QAAQpB,IAAImB,OAAO,CAACC,MAAM;YAC1B4D;YACAhF;QACF;IACF;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/routes/rest/buildFormState.ts"],"sourcesContent":["import type { BuildFormStateArgs } from '@payloadcms/ui/forms/buildStateFromSchema'\nimport type { DocumentPreferences, Field, PayloadRequestWithData, TypeWithID } from 'payload/types'\n\nimport { buildStateFromSchema } from '@payloadcms/ui/forms/buildStateFromSchema'\nimport { reduceFieldsToValues } from '@payloadcms/ui/utilities/reduceFieldsToValues'\nimport httpStatus from 'http-status'\n\nimport type { FieldSchemaMap } from '../../utilities/buildFieldSchemaMap/types.js'\n\nimport { buildFieldSchemaMap } from '../../utilities/buildFieldSchemaMap/index.js'\nimport { headersWithCors } from '../../utilities/headersWithCors.js'\nimport { routeError } from './routeError.js'\n\nlet cached = global._payload_fieldSchemaMap\n\nif (!cached) {\n // eslint-disable-next-line no-multi-assign\n cached = global._payload_fieldSchemaMap = null\n}\n\nexport const getFieldSchemaMap = (req: PayloadRequestWithData): FieldSchemaMap => {\n if (cached && process.env.NODE_ENV !== 'development') {\n return cached\n }\n\n cached = buildFieldSchemaMap(req)\n\n return cached\n}\n\nexport const buildFormState = async ({ req }: { req: PayloadRequestWithData }) => {\n const headers = headersWithCors({\n headers: new Headers(),\n req,\n })\n\n try {\n const reqData: BuildFormStateArgs = req.data as BuildFormStateArgs\n const { collectionSlug, formState, globalSlug, locale, operation, schemaPath } = reqData\n\n const incomingUserSlug = req.user?.collection\n const adminUserSlug = req.payload.config.admin.user\n\n // If we have a user slug, test it against the functions\n if (incomingUserSlug) {\n const adminAccessFunction = req.payload.collections[incomingUserSlug].config.access?.admin\n\n // Run the admin access function from the config if it exists\n if (adminAccessFunction) {\n const canAccessAdmin = await adminAccessFunction({ req })\n\n if (!canAccessAdmin) {\n return Response.json(null, {\n headers,\n status: httpStatus.UNAUTHORIZED,\n })\n }\n // Match the user collection to the global admin config\n } else if (adminUserSlug !== incomingUserSlug) {\n return Response.json(null, {\n headers,\n status: httpStatus.UNAUTHORIZED,\n })\n }\n } else {\n const hasUsers = await req.payload.find({\n collection: adminUserSlug,\n depth: 0,\n limit: 1,\n pagination: false,\n })\n // If there are users, we should not allow access because of /create-first-user\n if (hasUsers.docs.length) {\n return Response.json(null, {\n headers,\n status: httpStatus.UNAUTHORIZED,\n })\n }\n }\n\n const fieldSchemaMap = getFieldSchemaMap(req)\n\n const id = collectionSlug ? reqData.id : undefined\n const schemaPathSegments = schemaPath.split('.')\n\n let fieldSchema: Field[]\n\n if (schemaPathSegments.length === 1) {\n if (req.payload.collections[schemaPath]) {\n fieldSchema = req.payload.collections[schemaPath].config.fields\n } else {\n fieldSchema = req.payload.config.globals.find(\n (global) => global.slug === schemaPath,\n )?.fields\n }\n } else if (fieldSchemaMap.has(schemaPath)) {\n fieldSchema = fieldSchemaMap.get(schemaPath)\n }\n\n if (!fieldSchema) {\n return Response.json(\n {\n message: 'Could not find field schema for given path',\n },\n {\n headers,\n status: httpStatus.BAD_REQUEST,\n },\n )\n }\n\n let docPreferences = reqData.docPreferences\n let data = reqData.data\n\n const promises: {\n data?: Promise<void>\n preferences?: Promise<void>\n } = {}\n\n // If the request does not include doc preferences,\n // we should fetch them. This is useful for DocumentInfoProvider\n // as it reduces the amount of client-side fetches necessary\n // when we fetch data for the Edit view\n if (!docPreferences) {\n let preferencesKey\n\n if (collectionSlug && id) {\n preferencesKey = `collection-${collectionSlug}-${id}`\n }\n\n if (globalSlug) {\n preferencesKey = `global-${globalSlug}`\n }\n\n if (preferencesKey) {\n const fetchPreferences = async () => {\n const preferencesResult = (await req.payload.find({\n collection: 'payload-preferences',\n depth: 0,\n limit: 1,\n where: {\n key: {\n equals: preferencesKey,\n },\n },\n })) as unknown as { docs: { value: DocumentPreferences }[] }\n\n if (preferencesResult?.docs?.[0]?.value) docPreferences = preferencesResult.docs[0].value\n }\n\n promises.preferences = fetchPreferences()\n }\n }\n\n // If there is a form state,\n // then we can deduce data from that form state\n if (formState) data = reduceFieldsToValues(formState, true)\n\n // If we do not have data at this point,\n // we can fetch it. This is useful for DocumentInfoProvider\n // to reduce the amount of fetches required\n if (!data) {\n const fetchData = async () => {\n let resolvedData: TypeWithID\n\n if (collectionSlug && id) {\n resolvedData = await req.payload.findByID({\n id,\n collection: collectionSlug,\n depth: 0,\n draft: true,\n fallbackLocale: null,\n locale,\n overrideAccess: false,\n user: req.user,\n })\n }\n\n if (globalSlug && schemaPath === globalSlug) {\n resolvedData = await req.payload.findGlobal({\n slug: globalSlug,\n depth: 0,\n draft: true,\n fallbackLocale: null,\n locale,\n overrideAccess: false,\n user: req.user,\n })\n }\n\n data = resolvedData\n }\n\n promises.data = fetchData()\n }\n\n if (Object.keys(promises).length > 0) {\n await Promise.all(Object.values(promises))\n }\n\n const result = await buildStateFromSchema({\n id,\n data,\n fieldSchema,\n operation,\n preferences: docPreferences || { fields: {} },\n req,\n })\n\n // Maintain form state of auth / upload fields\n if (collectionSlug && formState) {\n if (req.payload.collections[collectionSlug]?.config?.upload && formState.file) {\n result.file = formState.file\n }\n\n if (\n req.payload.collections[collectionSlug]?.config?.auth &&\n !req.payload.collections[collectionSlug].config.auth.disableLocalStrategy\n ) {\n if (formState.password) result.password = formState.password\n if (formState['confirm-password'])\n result['confirm-password'] = formState['confirm-password']\n if (formState.email) result.email = formState.email\n }\n }\n\n return Response.json(result, {\n headers,\n status: httpStatus.OK,\n })\n } catch (err) {\n req.payload.logger.error({ err, msg: `There was an error building form state` })\n\n return routeError({\n config: req.payload.config,\n err,\n req,\n })\n }\n}\n"],"names":["buildStateFromSchema","reduceFieldsToValues","httpStatus","buildFieldSchemaMap","headersWithCors","routeError","cached","global","_payload_fieldSchemaMap","getFieldSchemaMap","req","process","env","NODE_ENV","buildFormState","headers","Headers","reqData","data","collectionSlug","formState","globalSlug","locale","operation","schemaPath","incomingUserSlug","user","collection","adminUserSlug","payload","config","admin","adminAccessFunction","collections","access","canAccessAdmin","Response","json","status","UNAUTHORIZED","hasUsers","find","depth","limit","pagination","docs","length","fieldSchemaMap","id","undefined","schemaPathSegments","split","fieldSchema","fields","globals","slug","has","get","message","BAD_REQUEST","docPreferences","promises","preferencesKey","fetchPreferences","preferencesResult","where","key","equals","value","preferences","fetchData","resolvedData","findByID","draft","fallbackLocale","overrideAccess","findGlobal","Object","keys","Promise","all","values","result","upload","file","auth","disableLocalStrategy","password","email","OK","err","logger","error","msg"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,SAASA,oBAAoB,QAAQ,4CAA2C;AAChF,SAASC,oBAAoB,QAAQ,gDAA+C;AACpF,OAAOC,gBAAgB,cAAa;AAIpC,SAASC,mBAAmB,QAAQ,+CAA8C;AAClF,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,UAAU,QAAQ,kBAAiB;AAE5C,IAAIC,SAASC,OAAOC,uBAAuB;AAE3C,IAAI,CAACF,QAAQ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D;YACA9B;YACAkC;YACA7B;YACA8C,aAAaT,kBAAkB;gBAAEP,QAAQ,CAAC;YAAE;YAC5C3C;QACF;QAEA,8CAA8C;QAC9C,IAAIS,kBAAkBC,WAAW;YAC/B,IAAIV,IAAImB,OAAO,CAACI,WAAW,CAACd,eAAe,EAAEW,QAAQqD,UAAU/D,UAAUgE,IAAI,EAAE;gBAC7EF,OAAOE,IAAI,GAAGhE,UAAUgE,IAAI;YAC9B;YAEA,IACE1E,IAAImB,OAAO,CAACI,WAAW,CAACd,eAAe,EAAEW,QAAQuD,QACjD,CAAC3E,IAAImB,OAAO,CAACI,WAAW,CAACd,eAAe,CAACW,MAAM,CAACuD,IAAI,CAACC,oBAAoB,EACzE;gBACA,IAAIlE,UAAUmE,QAAQ,EAAEL,OAAOK,QAAQ,GAAGnE,UAAUmE,QAAQ;gBAC5D,IAAInE,SAAS,CAAC,mBAAmB,EAC/B8D,MAAM,CAAC,mBAAmB,GAAG9D,SAAS,CAAC,mBAAmB;gBAC5D,IAAIA,UAAUoE,KAAK,EAAEN,OAAOM,KAAK,GAAGpE,UAAUoE,KAAK;YACrD;QACF;QAEA,OAAOpD,SAASC,IAAI,CAAC6C,QAAQ;YAC3BnE;YACAuB,QAAQpC,WAAWuF,EAAE;QACvB;IACF,EAAE,OAAOC,KAAK;QACZhF,IAAImB,OAAO,CAAC8D,MAAM,CAACC,KAAK,CAAC;YAAEF;YAAKG,KAAK,CAAC,sCAAsC,CAAC;QAAC;QAE9E,OAAOxF,WAAW;YAChByB,QAAQpB,IAAImB,OAAO,CAACC,MAAM;YAC1B4D;YACAhF;QACF;IACF;AACF,EAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Permissions } from 'payload/auth';
|
|
2
|
+
import type { SanitizedCollectionConfig, SanitizedConfig, SanitizedGlobalConfig } from 'payload/types';
|
|
3
|
+
export declare const handleAdminPage: ({ adminRoute, config, permissions, route, }: {
|
|
4
|
+
adminRoute: string;
|
|
5
|
+
config: SanitizedConfig;
|
|
6
|
+
permissions: Permissions;
|
|
7
|
+
route: string;
|
|
8
|
+
}) => {
|
|
9
|
+
collectionConfig: SanitizedCollectionConfig;
|
|
10
|
+
docID: string;
|
|
11
|
+
globalConfig: SanitizedGlobalConfig;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=handleAdminPage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleAdminPage.d.ts","sourceRoot":"","sources":["../../../src/utilities/initPage/handleAdminPage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,KAAK,EACV,yBAAyB,EACzB,eAAe,EACf,qBAAqB,EACtB,MAAM,eAAe,CAAA;AAMtB,eAAO,MAAM,eAAe,gDAKzB;IACD,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,eAAe,CAAA;IACvB,WAAW,EAAE,WAAW,CAAA;IACxB,KAAK,EAAE,MAAM,CAAA;CACd;;;;CAqCA,CAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { notFound } from 'next/navigation.js';
|
|
2
|
+
import { isAdminAuthRoute, isAdminRoute } from './shared.js';
|
|
3
|
+
export const handleAdminPage = ({ adminRoute, config, permissions, route })=>{
|
|
4
|
+
if (isAdminRoute(route, adminRoute)) {
|
|
5
|
+
const routeSegments = route.replace(adminRoute, '').split('/').filter(Boolean);
|
|
6
|
+
const [entityType, entitySlug, createOrID] = routeSegments;
|
|
7
|
+
const collectionSlug = entityType === 'collections' ? entitySlug : undefined;
|
|
8
|
+
const globalSlug = entityType === 'globals' ? entitySlug : undefined;
|
|
9
|
+
const docID = collectionSlug && createOrID !== 'create' ? createOrID : undefined;
|
|
10
|
+
let collectionConfig;
|
|
11
|
+
let globalConfig;
|
|
12
|
+
if (collectionSlug) {
|
|
13
|
+
collectionConfig = config.collections.find((collection)=>collection.slug === collectionSlug);
|
|
14
|
+
if (!collectionConfig) {
|
|
15
|
+
notFound();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (globalSlug) {
|
|
19
|
+
globalConfig = config.globals.find((global)=>global.slug === globalSlug);
|
|
20
|
+
if (!globalConfig) {
|
|
21
|
+
notFound();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (!permissions.canAccessAdmin && !isAdminAuthRoute(route, adminRoute)) {
|
|
25
|
+
notFound();
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
collectionConfig,
|
|
29
|
+
docID,
|
|
30
|
+
globalConfig
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=handleAdminPage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utilities/initPage/handleAdminPage.ts"],"sourcesContent":["import type { Permissions } from 'payload/auth'\nimport type {\n SanitizedCollectionConfig,\n SanitizedConfig,\n SanitizedGlobalConfig,\n} from 'payload/types'\n\nimport { notFound } from 'next/navigation.js'\n\nimport { isAdminAuthRoute, isAdminRoute } from './shared.js'\n\nexport const handleAdminPage = ({\n adminRoute,\n config,\n permissions,\n route,\n}: {\n adminRoute: string\n config: SanitizedConfig\n permissions: Permissions\n route: string\n}) => {\n if (isAdminRoute(route, adminRoute)) {\n const routeSegments = route.replace(adminRoute, '').split('/').filter(Boolean)\n const [entityType, entitySlug, createOrID] = routeSegments\n const collectionSlug = entityType === 'collections' ? entitySlug : undefined\n const globalSlug = entityType === 'globals' ? entitySlug : undefined\n const docID = collectionSlug && createOrID !== 'create' ? createOrID : undefined\n\n let collectionConfig: SanitizedCollectionConfig | undefined\n let globalConfig: SanitizedGlobalConfig | undefined\n\n if (collectionSlug) {\n collectionConfig = config.collections.find((collection) => collection.slug === collectionSlug)\n\n if (!collectionConfig) {\n notFound()\n }\n }\n\n if (globalSlug) {\n globalConfig = config.globals.find((global) => global.slug === globalSlug)\n\n if (!globalConfig) {\n notFound()\n }\n }\n\n if (!permissions.canAccessAdmin && !isAdminAuthRoute(route, adminRoute)) {\n notFound()\n }\n\n return {\n collectionConfig,\n docID,\n globalConfig,\n }\n }\n}\n"],"names":["notFound","isAdminAuthRoute","isAdminRoute","handleAdminPage","adminRoute","config","permissions","route","routeSegments","replace","split","filter","Boolean","entityType","entitySlug","createOrID","collectionSlug","undefined","globalSlug","docID","collectionConfig","globalConfig","collections","find","collection","slug","globals","global","canAccessAdmin"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAOA,SAASA,QAAQ,QAAQ,qBAAoB;AAE7C,SAASC,gBAAgB,EAAEC,YAAY,QAAQ,cAAa;AAE5D,OAAO,MAAMC,kBAAkB,CAAC,EAC9BC,UAAU,EACVC,MAAM,EACNC,WAAW,EACXC,KAAK,EAMN;IACC,IAAIL,aAAaK,OAAOH,aAAa;QACnC,MAAMI,gBAAgBD,MAAME,OAAO,CAACL,YAAY,IAAIM,KAAK,CAAC,KAAKC,MAAM,CAACC;QACtE,MAAM,CAACC,YAAYC,YAAYC,WAAW,GAAGP;QAC7C,MAAMQ,iBAAiBH,eAAe,gBAAgBC,aAAaG;QACnE,MAAMC,aAAaL,eAAe,YAAYC,aAAaG;QAC3D,MAAME,QAAQH,kBAAkBD,eAAe,WAAWA,aAAaE;QAEvE,IAAIG;QACJ,IAAIC;QAEJ,IAAIL,gBAAgB;YAClBI,mBAAmBf,OAAOiB,WAAW,CAACC,IAAI,CAAC,CAACC,aAAeA,WAAWC,IAAI,KAAKT;YAE/E,IAAI,CAACI,kBAAkB;gBACrBpB;YACF;QACF;QAEA,IAAIkB,YAAY;YACdG,eAAehB,OAAOqB,OAAO,CAACH,IAAI,CAAC,CAACI,SAAWA,OAAOF,IAAI,KAAKP;YAE/D,IAAI,CAACG,cAAc;gBACjBrB;YACF;QACF;QAEA,IAAI,CAACM,YAAYsB,cAAc,IAAI,CAAC3B,iBAAiBM,OAAOH,aAAa;YACvEJ;QACF;QAEA,OAAO;YACLoB;YACAD;YACAE;QACF;IACF;AACF,EAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const handleAuthRedirect: ({ adminRoute, redirectUnauthenticatedUser, route, searchParams, }: {
|
|
2
|
+
adminRoute: string;
|
|
3
|
+
redirectUnauthenticatedUser: boolean | string;
|
|
4
|
+
route: string;
|
|
5
|
+
searchParams: {
|
|
6
|
+
[key: string]: string | string[];
|
|
7
|
+
};
|
|
8
|
+
}) => void;
|
|
9
|
+
//# sourceMappingURL=handleAuthRedirect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleAuthRedirect.d.ts","sourceRoot":"","sources":["../../../src/utilities/initPage/handleAuthRedirect.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,kBAAkB,sEAK5B;IACD,UAAU,EAAE,MAAM,CAAA;IAClB,2BAA2B,EAAE,OAAO,GAAG,MAAM,CAAA;IAC7C,KAAK,EAAE,MAAM,CAAA;IACb,YAAY,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAA;KAAE,CAAA;CACnD,SA+BA,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { redirect } from 'next/navigation.js';
|
|
2
|
+
import QueryString from 'qs';
|
|
3
|
+
import { isAdminAuthRoute, isAdminRoute } from './shared.js';
|
|
4
|
+
export const handleAuthRedirect = ({ adminRoute, redirectUnauthenticatedUser, route, searchParams })=>{
|
|
5
|
+
if (!isAdminAuthRoute(route, adminRoute)) {
|
|
6
|
+
if (searchParams && 'redirect' in searchParams) delete searchParams.redirect;
|
|
7
|
+
const redirectRoute = encodeURIComponent(route + Object.keys(searchParams ?? {}).length ? `${QueryString.stringify(searchParams, {
|
|
8
|
+
addQueryPrefix: true
|
|
9
|
+
})}` : undefined);
|
|
10
|
+
const adminLoginRoute = `${adminRoute}/login`;
|
|
11
|
+
const customLoginRoute = typeof redirectUnauthenticatedUser === 'string' ? redirectUnauthenticatedUser : undefined;
|
|
12
|
+
const loginRoute = isAdminRoute(route, adminRoute) ? adminLoginRoute : customLoginRoute || '/login';
|
|
13
|
+
const parsedLoginRouteSearchParams = QueryString.parse(loginRoute.split('?')[1] ?? '');
|
|
14
|
+
const searchParamsWithRedirect = `${QueryString.stringify({
|
|
15
|
+
...parsedLoginRouteSearchParams,
|
|
16
|
+
...redirectRoute ? {
|
|
17
|
+
redirect: redirectRoute
|
|
18
|
+
} : {}
|
|
19
|
+
}, {
|
|
20
|
+
addQueryPrefix: true
|
|
21
|
+
})}`;
|
|
22
|
+
redirect(`${loginRoute.split('?')[0]}${searchParamsWithRedirect}`);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=handleAuthRedirect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utilities/initPage/handleAuthRedirect.ts"],"sourcesContent":["import { redirect } from 'next/navigation.js'\nimport QueryString from 'qs'\n\nimport { isAdminAuthRoute, isAdminRoute } from './shared.js'\n\nexport const handleAuthRedirect = ({\n adminRoute,\n redirectUnauthenticatedUser,\n route,\n searchParams,\n}: {\n adminRoute: string\n redirectUnauthenticatedUser: boolean | string\n route: string\n searchParams: { [key: string]: string | string[] }\n}) => {\n if (!isAdminAuthRoute(route, adminRoute)) {\n if (searchParams && 'redirect' in searchParams) delete searchParams.redirect\n\n const redirectRoute = encodeURIComponent(\n route + Object.keys(searchParams ?? {}).length\n ? `${QueryString.stringify(searchParams, { addQueryPrefix: true })}`\n : undefined,\n )\n\n const adminLoginRoute = `${adminRoute}/login`\n\n const customLoginRoute =\n typeof redirectUnauthenticatedUser === 'string' ? redirectUnauthenticatedUser : undefined\n\n const loginRoute = isAdminRoute(route, adminRoute)\n ? adminLoginRoute\n : customLoginRoute || '/login'\n\n const parsedLoginRouteSearchParams = QueryString.parse(loginRoute.split('?')[1] ?? '')\n\n const searchParamsWithRedirect = `${QueryString.stringify(\n {\n ...parsedLoginRouteSearchParams,\n ...(redirectRoute ? { redirect: redirectRoute } : {}),\n },\n { addQueryPrefix: true },\n )}`\n\n redirect(`${loginRoute.split('?')[0]}${searchParamsWithRedirect}`)\n }\n}\n"],"names":["redirect","QueryString","isAdminAuthRoute","isAdminRoute","handleAuthRedirect","adminRoute","redirectUnauthenticatedUser","route","searchParams","redirectRoute","encodeURIComponent","Object","keys","length","stringify","addQueryPrefix","undefined","adminLoginRoute","customLoginRoute","loginRoute","parsedLoginRouteSearchParams","parse","split","searchParamsWithRedirect"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,QAAQ,QAAQ,qBAAoB;AAC7C,OAAOC,iBAAiB,KAAI;AAE5B,SAASC,gBAAgB,EAAEC,YAAY,QAAQ,cAAa;AAE5D,OAAO,MAAMC,qBAAqB,CAAC,EACjCC,UAAU,EACVC,2BAA2B,EAC3BC,KAAK,EACLC,YAAY,EAMb;IACC,IAAI,CAACN,iBAAiBK,OAAOF,aAAa;QACxC,IAAIG,gBAAgB,cAAcA,cAAc,OAAOA,aAAaR,QAAQ;QAE5E,MAAMS,gBAAgBC,mBACpBH,QAAQI,OAAOC,IAAI,CAACJ,gBAAgB,CAAC,GAAGK,MAAM,GAC1C,CAAC,EAAEZ,YAAYa,SAAS,CAACN,cAAc;YAAEO,gBAAgB;QAAK,GAAG,CAAC,GAClEC;QAGN,MAAMC,kBAAkB,CAAC,EAAEZ,WAAW,MAAM,CAAC;QAE7C,MAAMa,mBACJ,OAAOZ,gCAAgC,WAAWA,8BAA8BU;QAElF,MAAMG,aAAahB,aAAaI,OAAOF,cACnCY,kBACAC,oBAAoB;QAExB,MAAME,+BAA+BnB,YAAYoB,KAAK,CAACF,WAAWG,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI;QAEnF,MAAMC,2BAA2B,CAAC,EAAEtB,YAAYa,SAAS,CACvD;YACE,GAAGM,4BAA4B;YAC/B,GAAIX,gBAAgB;gBAAET,UAAUS;YAAc,IAAI,CAAC,CAAC;QACtD,GACA;YAAEM,gBAAgB;QAAK,GACvB,CAAC;QAEHf,SAAS,CAAC,EAAEmB,WAAWG,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,EAAEC,yBAAyB,CAAC;IACnE;AACF,EAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { InitPageResult } from 'payload/types';
|
|
2
|
+
import type { Args } from './types.js';
|
|
3
|
+
export declare const initPage: ({ config: configPromise, redirectUnauthenticatedUser, route, searchParams, }: Args) => Promise<InitPageResult>;
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utilities/initPage/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAA2C,MAAM,eAAe,CAAA;AAS5F,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAOtC,eAAO,MAAM,QAAQ,iFAKlB,IAAI,KAAG,QAAQ,cAAc,CAmF/B,CAAA"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { initI18n } from '@payloadcms/translations';
|
|
2
|
+
import { findLocaleFromCode } from '@payloadcms/ui/utilities/findLocaleFromCode';
|
|
3
|
+
import { headers as getHeaders } from 'next/headers.js';
|
|
4
|
+
import { parseCookies } from 'payload/auth';
|
|
5
|
+
import { createLocalReq, isEntityHidden } from 'payload/utilities';
|
|
6
|
+
import qs from 'qs';
|
|
7
|
+
import { getPayloadHMR } from '../getPayloadHMR.js';
|
|
8
|
+
import { getRequestLanguage } from '../getRequestLanguage.js';
|
|
9
|
+
import { handleAdminPage } from './handleAdminPage.js';
|
|
10
|
+
import { handleAuthRedirect } from './handleAuthRedirect.js';
|
|
11
|
+
export const initPage = async ({ config: configPromise, redirectUnauthenticatedUser = false, route, searchParams })=>{
|
|
12
|
+
const headers = getHeaders();
|
|
13
|
+
const localeParam = searchParams?.locale;
|
|
14
|
+
const payload = await getPayloadHMR({
|
|
15
|
+
config: configPromise
|
|
16
|
+
});
|
|
17
|
+
const { collections, globals, i18n: i18nConfig, localization, routes: { admin: adminRoute } } = payload.config;
|
|
18
|
+
const queryString = `${qs.stringify(searchParams ?? {}, {
|
|
19
|
+
addQueryPrefix: true
|
|
20
|
+
})}`;
|
|
21
|
+
const defaultLocale = localization && localization.defaultLocale ? localization.defaultLocale : 'en';
|
|
22
|
+
const localeCode = localeParam || defaultLocale;
|
|
23
|
+
const locale = localization && findLocaleFromCode(localization, localeCode);
|
|
24
|
+
const cookies = parseCookies(headers);
|
|
25
|
+
const language = getRequestLanguage({
|
|
26
|
+
config: payload.config,
|
|
27
|
+
cookies,
|
|
28
|
+
headers
|
|
29
|
+
});
|
|
30
|
+
const i18n = await initI18n({
|
|
31
|
+
config: i18nConfig,
|
|
32
|
+
context: 'client',
|
|
33
|
+
language
|
|
34
|
+
});
|
|
35
|
+
const req = await createLocalReq({
|
|
36
|
+
fallbackLocale: null,
|
|
37
|
+
locale: locale.code,
|
|
38
|
+
req: {
|
|
39
|
+
i18n,
|
|
40
|
+
query: qs.parse(queryString, {
|
|
41
|
+
depth: 10,
|
|
42
|
+
ignoreQueryPrefix: true
|
|
43
|
+
}),
|
|
44
|
+
url: `${payload.config.serverURL}${route}${searchParams ? queryString : ''}`
|
|
45
|
+
}
|
|
46
|
+
}, payload);
|
|
47
|
+
const { permissions, user } = await payload.auth({
|
|
48
|
+
headers,
|
|
49
|
+
req
|
|
50
|
+
});
|
|
51
|
+
req.user = user;
|
|
52
|
+
const visibleEntities = {
|
|
53
|
+
collections: collections.map(({ slug, admin: { hidden } })=>!isEntityHidden({
|
|
54
|
+
hidden,
|
|
55
|
+
user
|
|
56
|
+
}) ? slug : null).filter(Boolean),
|
|
57
|
+
globals: globals.map(({ slug, admin: { hidden } })=>!isEntityHidden({
|
|
58
|
+
hidden,
|
|
59
|
+
user
|
|
60
|
+
}) ? slug : null).filter(Boolean)
|
|
61
|
+
};
|
|
62
|
+
if (redirectUnauthenticatedUser && !user) {
|
|
63
|
+
handleAuthRedirect({
|
|
64
|
+
adminRoute,
|
|
65
|
+
redirectUnauthenticatedUser,
|
|
66
|
+
route,
|
|
67
|
+
searchParams
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
const { collectionConfig, docID, globalConfig } = handleAdminPage({
|
|
71
|
+
adminRoute,
|
|
72
|
+
config: payload.config,
|
|
73
|
+
permissions,
|
|
74
|
+
route
|
|
75
|
+
});
|
|
76
|
+
return {
|
|
77
|
+
collectionConfig,
|
|
78
|
+
cookies,
|
|
79
|
+
docID,
|
|
80
|
+
globalConfig,
|
|
81
|
+
locale,
|
|
82
|
+
permissions,
|
|
83
|
+
req,
|
|
84
|
+
translations: i18n.translations,
|
|
85
|
+
visibleEntities
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utilities/initPage/index.ts"],"sourcesContent":["import type { InitPageResult, PayloadRequestWithData, VisibleEntities } from 'payload/types'\n\nimport { initI18n } from '@payloadcms/translations'\nimport { findLocaleFromCode } from '@payloadcms/ui/utilities/findLocaleFromCode'\nimport { headers as getHeaders } from 'next/headers.js'\nimport { parseCookies } from 'payload/auth'\nimport { createLocalReq, isEntityHidden } from 'payload/utilities'\nimport qs from 'qs'\n\nimport type { Args } from './types.js'\n\nimport { getPayloadHMR } from '../getPayloadHMR.js'\nimport { getRequestLanguage } from '../getRequestLanguage.js'\nimport { handleAdminPage } from './handleAdminPage.js'\nimport { handleAuthRedirect } from './handleAuthRedirect.js'\n\nexport const initPage = async ({\n config: configPromise,\n redirectUnauthenticatedUser = false,\n route,\n searchParams,\n}: Args): Promise<InitPageResult> => {\n const headers = getHeaders()\n const localeParam = searchParams?.locale as string\n const payload = await getPayloadHMR({ config: configPromise })\n\n const {\n collections,\n globals,\n i18n: i18nConfig,\n localization,\n routes: { admin: adminRoute },\n } = payload.config\n\n const queryString = `${qs.stringify(searchParams ?? {}, { addQueryPrefix: true })}`\n const defaultLocale =\n localization && localization.defaultLocale ? localization.defaultLocale : 'en'\n const localeCode = localeParam || defaultLocale\n const locale = localization && findLocaleFromCode(localization, localeCode)\n const cookies = parseCookies(headers)\n const language = getRequestLanguage({ config: payload.config, cookies, headers })\n\n const i18n = await initI18n({\n config: i18nConfig,\n context: 'client',\n language,\n })\n\n const req = await createLocalReq(\n {\n fallbackLocale: null,\n locale: locale.code,\n req: {\n i18n,\n query: qs.parse(queryString, {\n depth: 10,\n ignoreQueryPrefix: true,\n }),\n url: `${payload.config.serverURL}${route}${searchParams ? queryString : ''}`,\n } as PayloadRequestWithData,\n },\n payload,\n )\n\n const { permissions, user } = await payload.auth({ headers, req })\n\n req.user = user\n\n const visibleEntities: VisibleEntities = {\n collections: collections\n .map(({ slug, admin: { hidden } }) => (!isEntityHidden({ hidden, user }) ? slug : null))\n .filter(Boolean),\n globals: globals\n .map(({ slug, admin: { hidden } }) => (!isEntityHidden({ hidden, user }) ? slug : null))\n .filter(Boolean),\n }\n\n if (redirectUnauthenticatedUser && !user) {\n handleAuthRedirect({\n adminRoute,\n redirectUnauthenticatedUser,\n route,\n searchParams,\n })\n }\n\n const { collectionConfig, docID, globalConfig } = handleAdminPage({\n adminRoute,\n config: payload.config,\n permissions,\n route,\n })\n\n return {\n collectionConfig,\n cookies,\n docID,\n globalConfig,\n locale,\n permissions,\n req,\n translations: i18n.translations,\n visibleEntities,\n }\n}\n"],"names":["initI18n","findLocaleFromCode","headers","getHeaders","parseCookies","createLocalReq","isEntityHidden","qs","getPayloadHMR","getRequestLanguage","handleAdminPage","handleAuthRedirect","initPage","config","configPromise","redirectUnauthenticatedUser","route","searchParams","localeParam","locale","payload","collections","globals","i18n","i18nConfig","localization","routes","admin","adminRoute","queryString","stringify","addQueryPrefix","defaultLocale","localeCode","cookies","language","context","req","fallbackLocale","code","query","parse","depth","ignoreQueryPrefix","url","serverURL","permissions","user","auth","visibleEntities","map","slug","hidden","filter","Boolean","collectionConfig","docID","globalConfig","translations"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,kBAAkB,QAAQ,8CAA6C;AAChF,SAASC,WAAWC,UAAU,QAAQ,kBAAiB;AACvD,SAASC,YAAY,QAAQ,eAAc;AAC3C,SAASC,cAAc,EAAEC,cAAc,QAAQ,oBAAmB;AAClE,OAAOC,QAAQ,KAAI;AAInB,SAASC,aAAa,QAAQ,sBAAqB;AACnD,SAASC,kBAAkB,QAAQ,2BAA0B;AAC7D,SAASC,eAAe,QAAQ,uBAAsB;AACtD,SAASC,kBAAkB,QAAQ,0BAAyB;AAE5D,OAAO,MAAMC,WAAW,OAAO,EAC7BC,QAAQC,aAAa,EACrBC,8BAA8B,KAAK,EACnCC,KAAK,EACLC,YAAY,EACP;IACL,MAAMf,UAAUC;IAChB,MAAMe,cAAcD,cAAcE;IAClC,MAAMC,UAAU,MAAMZ,cAAc;QAAEK,QAAQC;IAAc;IAE5D,MAAM,EACJO,WAAW,EACXC,OAAO,EACPC,MAAMC,UAAU,EAChBC,YAAY,EACZC,QAAQ,EAAEC,OAAOC,UAAU,EAAE,EAC9B,GAAGR,QAAQP,MAAM;IAElB,MAAMgB,cAAc,CAAC,EAAEtB,GAAGuB,SAAS,CAACb,gBAAgB,CAAC,GAAG;QAAEc,gBAAgB;IAAK,GAAG,CAAC;IACnF,MAAMC,gBACJP,gBAAgBA,aAAaO,aAAa,GAAGP,aAAaO,aAAa,GAAG;IAC5E,MAAMC,aAAaf,eAAec;IAClC,MAAMb,SAASM,gBAAgBxB,mBAAmBwB,cAAcQ;IAChE,MAAMC,UAAU9B,aAA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ACA2B;QACAT;QACAqB,cAAcnC,KAAKmC,YAAY;QAC/BT;IACF;AACF,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../src/utilities/initPage/shared.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,UAQtB,CAAA;AAED,eAAO,MAAM,YAAY,UAAW,MAAM,cAAc,MAAM,YAE7D,CAAA;AAED,eAAO,MAAM,gBAAgB,UAAW,MAAM,cAAc,MAAM,YAEjE,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const authRoutes = [
|
|
2
|
+
'/login',
|
|
3
|
+
'/logout',
|
|
4
|
+
'/create-first-user',
|
|
5
|
+
'/forgot',
|
|
6
|
+
'/reset',
|
|
7
|
+
'/verify',
|
|
8
|
+
'/logout-inactivity'
|
|
9
|
+
];
|
|
10
|
+
export const isAdminRoute = (route, adminRoute)=>{
|
|
11
|
+
return route.startsWith(adminRoute);
|
|
12
|
+
};
|
|
13
|
+
export const isAdminAuthRoute = (route, adminRoute)=>{
|
|
14
|
+
return authRoutes.some((r)=>route.replace(adminRoute, '').startsWith(r));
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utilities/initPage/shared.ts"],"sourcesContent":["export const authRoutes = [\n '/login',\n '/logout',\n '/create-first-user',\n '/forgot',\n '/reset',\n '/verify',\n '/logout-inactivity',\n]\n\nexport const isAdminRoute = (route: string, adminRoute: string) => {\n return route.startsWith(adminRoute)\n}\n\nexport const isAdminAuthRoute = (route: string, adminRoute: string) => {\n return authRoutes.some((r) => route.replace(adminRoute, '').startsWith(r))\n}\n"],"names":["authRoutes","isAdminRoute","route","adminRoute","startsWith","isAdminAuthRoute","some","r","replace"],"rangeMappings":";;;;;;;;;;;;;;","mappings":"AAAA,OAAO,MAAMA,aAAa;IACxB;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAA;AAED,OAAO,MAAMC,eAAe,CAACC,OAAeC;IAC1C,OAAOD,MAAME,UAAU,CAACD;AAC1B,EAAC;AAED,OAAO,MAAME,mBAAmB,CAACH,OAAeC;IAC9C,OAAOH,WAAWM,IAAI,CAAC,CAACC,IAAML,MAAMM,OAAO,CAACL,YAAY,IAAIC,UAAU,CAACG;AACzE,EAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { SanitizedConfig } from 'payload/types';
|
|
2
|
+
export type Args = {
|
|
3
|
+
/**
|
|
4
|
+
* Your sanitized Payload config.
|
|
5
|
+
* If unresolved, this function will await the promise.
|
|
6
|
+
*/
|
|
7
|
+
config: Promise<SanitizedConfig> | SanitizedConfig;
|
|
8
|
+
/**
|
|
9
|
+
* If true, redirects unauthenticated users to the admin login page.
|
|
10
|
+
* If a string is provided, the user will be redirected to that specific URL.
|
|
11
|
+
*/
|
|
12
|
+
redirectUnauthenticatedUser?: boolean | string;
|
|
13
|
+
/**
|
|
14
|
+
* The current route, i.e. `/admin/collections/posts`.
|
|
15
|
+
*/
|
|
16
|
+
route: string;
|
|
17
|
+
/**
|
|
18
|
+
* The search parameters of the current route provided to all pages in Next.js.
|
|
19
|
+
*/
|
|
20
|
+
searchParams: {
|
|
21
|
+
[key: string]: string | string[] | undefined;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/utilities/initPage/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAEpD,MAAM,MAAM,IAAI,GAAG;IACjB;;;OAGG;IACH,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,CAAA;IAClD;;;OAGG;IACH,2BAA2B,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IAC9C;;OAEG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;OAEG;IACH,YAAY,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAA;KAAE,CAAA;CAC/D,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utilities/initPage/types.ts"],"sourcesContent":["import type { SanitizedConfig } from 'payload/types'\n\nexport type Args = {\n /**\n * Your sanitized Payload config.\n * If unresolved, this function will await the promise.\n */\n config: Promise<SanitizedConfig> | SanitizedConfig\n /**\n * If true, redirects unauthenticated users to the admin login page.\n * If a string is provided, the user will be redirected to that specific URL.\n */\n redirectUnauthenticatedUser?: boolean | string\n /**\n * The current route, i.e. `/admin/collections/posts`.\n */\n route: string\n /**\n * The search parameters of the current route provided to all pages in Next.js.\n */\n searchParams: { [key: string]: string | string[] | undefined }\n}\n"],"names":[],"rangeMappings":"","mappings":"AAEA,WAmBC"}
|
|
@@ -2,7 +2,7 @@ import { HydrateClientUser } from '@payloadcms/ui/elements/HydrateClientUser';
|
|
|
2
2
|
import { DefaultTemplate } from '@payloadcms/ui/templates/Default';
|
|
3
3
|
import React, { Fragment } from 'react';
|
|
4
4
|
import { getNextRequestI18n } from '../../utilities/getNextRequestI18n.js';
|
|
5
|
-
import { initPage } from '../../utilities/initPage.js';
|
|
5
|
+
import { initPage } from '../../utilities/initPage/index.js';
|
|
6
6
|
import { NotFoundClient } from './index.client.js';
|
|
7
7
|
export const generatePageMetadata = async ({ config: configPromise })=>{
|
|
8
8
|
const config = await configPromise;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/views/NotFound/index.tsx"],"sourcesContent":["import type { I18n } from '@payloadcms/translations'\nimport type { Metadata } from 'next'\nimport type { AdminViewComponent, SanitizedConfig } from 'payload/types'\n\nimport { HydrateClientUser } from '@payloadcms/ui/elements/HydrateClientUser'\nimport { DefaultTemplate } from '@payloadcms/ui/templates/Default'\nimport React, { Fragment } from 'react'\n\nimport { getNextRequestI18n } from '../../utilities/getNextRequestI18n.js'\nimport { initPage } from '../../utilities/initPage.js'\nimport { NotFoundClient } from './index.client.js'\n\nexport const generatePageMetadata = async ({\n config: configPromise,\n}: {\n config: Promise<SanitizedConfig> | SanitizedConfig\n params?: { [key: string]: string | string[] }\n //eslint-disable-next-line @typescript-eslint/require-await\n}): Promise<Metadata> => {\n const config = await configPromise\n\n const i18n = await getNextRequestI18n({\n config,\n })\n\n return {\n title: i18n.t('general:notFound'),\n }\n}\n\nexport type GenerateViewMetadata = (args: {\n config: SanitizedConfig\n i18n: I18n\n params?: { [key: string]: string | string[] }\n}) => Promise<Metadata>\n\nexport const NotFoundPage = async ({\n config: configPromise,\n searchParams,\n}: {\n config: Promise<SanitizedConfig>\n params: {\n segments: string[]\n }\n searchParams: {\n [key: string]: string | string[]\n }\n}) => {\n const config = await configPromise\n const { routes: { admin: adminRoute } = {} } = config\n\n const initPageResult = await initPage({\n config,\n redirectUnauthenticatedUser: true,\n route: `${adminRoute}/not-found`,\n searchParams,\n })\n\n return (\n <Fragment>\n <HydrateClientUser permissions={initPageResult.permissions} user={initPageResult.req.user} />\n <DefaultTemplate\n config={initPageResult.req.payload.config}\n visibleEntities={initPageResult.visibleEntities}\n >\n <NotFoundClient />\n </DefaultTemplate>\n </Fragment>\n )\n}\n\nexport const NotFoundView: AdminViewComponent = () => {\n return <NotFoundClient marginTop=\"large\" />\n}\n"],"names":["HydrateClientUser","DefaultTemplate","React","Fragment","getNextRequestI18n","initPage","NotFoundClient","generatePageMetadata","config","configPromise","i18n","title","t","NotFoundPage","searchParams","routes","admin","adminRoute","initPageResult","redirectUnauthenticatedUser","route","permissions","user","req","payload","visibleEntities","NotFoundView","marginTop"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,iBAAiB,QAAQ,4CAA2C;AAC7E,SAASC,eAAe,QAAQ,mCAAkC;AAClE,OAAOC,SAASC,QAAQ,QAAQ,QAAO;AAEvC,SAASC,kBAAkB,QAAQ,wCAAuC;AAC1E,SAASC,QAAQ,QAAQ,
|
|
1
|
+
{"version":3,"sources":["../../../src/views/NotFound/index.tsx"],"sourcesContent":["import type { I18n } from '@payloadcms/translations'\nimport type { Metadata } from 'next'\nimport type { AdminViewComponent, SanitizedConfig } from 'payload/types'\n\nimport { HydrateClientUser } from '@payloadcms/ui/elements/HydrateClientUser'\nimport { DefaultTemplate } from '@payloadcms/ui/templates/Default'\nimport React, { Fragment } from 'react'\n\nimport { getNextRequestI18n } from '../../utilities/getNextRequestI18n.js'\nimport { initPage } from '../../utilities/initPage/index.js'\nimport { NotFoundClient } from './index.client.js'\n\nexport const generatePageMetadata = async ({\n config: configPromise,\n}: {\n config: Promise<SanitizedConfig> | SanitizedConfig\n params?: { [key: string]: string | string[] }\n //eslint-disable-next-line @typescript-eslint/require-await\n}): Promise<Metadata> => {\n const config = await configPromise\n\n const i18n = await getNextRequestI18n({\n config,\n })\n\n return {\n title: i18n.t('general:notFound'),\n }\n}\n\nexport type GenerateViewMetadata = (args: {\n config: SanitizedConfig\n i18n: I18n\n params?: { [key: string]: string | string[] }\n}) => Promise<Metadata>\n\nexport const NotFoundPage = async ({\n config: configPromise,\n searchParams,\n}: {\n config: Promise<SanitizedConfig>\n params: {\n segments: string[]\n }\n searchParams: {\n [key: string]: string | string[]\n }\n}) => {\n const config = await configPromise\n const { routes: { admin: adminRoute } = {} } = config\n\n const initPageResult = await initPage({\n config,\n redirectUnauthenticatedUser: true,\n route: `${adminRoute}/not-found`,\n searchParams,\n })\n\n return (\n <Fragment>\n <HydrateClientUser permissions={initPageResult.permissions} user={initPageResult.req.user} />\n <DefaultTemplate\n config={initPageResult.req.payload.config}\n visibleEntities={initPageResult.visibleEntities}\n >\n <NotFoundClient />\n </DefaultTemplate>\n </Fragment>\n )\n}\n\nexport const NotFoundView: AdminViewComponent = () => {\n return <NotFoundClient marginTop=\"large\" />\n}\n"],"names":["HydrateClientUser","DefaultTemplate","React","Fragment","getNextRequestI18n","initPage","NotFoundClient","generatePageMetadata","config","configPromise","i18n","title","t","NotFoundPage","searchParams","routes","admin","adminRoute","initPageResult","redirectUnauthenticatedUser","route","permissions","user","req","payload","visibleEntities","NotFoundView","marginTop"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,iBAAiB,QAAQ,4CAA2C;AAC7E,SAASC,eAAe,QAAQ,mCAAkC;AAClE,OAAOC,SAASC,QAAQ,QAAQ,QAAO;AAEvC,SAASC,kBAAkB,QAAQ,wCAAuC;AAC1E,SAASC,QAAQ,QAAQ,oCAAmC;AAC5D,SAASC,cAAc,QAAQ,oBAAmB;AAElD,OAAO,MAAMC,uBAAuB,OAAO,EACzCC,QAAQC,aAAa,EAKtB;IACC,MAAMD,SAAS,MAAMC;IAErB,MAAMC,OAAO,MAAMN,mBAAmB;QACpCI;IACF;IAEA,OAAO;QACLG,OAAOD,KAAKE,CAAC,CAAC;IAChB;AACF,EAAC;AAQD,OAAO,MAAMC,eAAe,OAAO,EACjCL,QAAQC,aAAa,EACrBK,YAAY,EASb;IACC,MAAMN,SAAS,MAAMC;IACrB,MAAM,EAAEM,QAAQ,EAAEC,OAAOC,UAAU,EAAE,GAAG,CAAC,CAAC,EAAE,GAAGT;IAE/C,MAAMU,iBAAiB,MAAMb,SAAS;QACpCG;QACAW,6BAA6B;QAC7BC,OAAO,CAAC,EAAEH,WAAW,UAAU,CAAC;QAChCH;IACF;IAEA,qBACE,oBAACX,8BACC,oBAACH;QAAkBqB,aAAaH,eAAeG,WAAW;QAAEC,MAAMJ,eAAeK,GAAG,CAACD,IAAI;sBACzF,oBAACrB;QACCO,QAAQU,eAAeK,GAAG,CAACC,OAAO,CAAChB,MAAM;QACzCiB,iBAAiBP,eAAeO,eAAe;qBAE/C,oBAACnB;AAIT,EAAC;AAED,OAAO,MAAMoB,eAAmC;IAC9C,qBAAO,oBAACpB;QAAeqB,WAAU;;AACnC,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.client.d.ts","sourceRoot":"","sources":["../../../src/views/ResetPassword/index.client.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,KAAK,IAAI,GAAG;IACV,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAeD,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC,IAAI,CAsC9C,CAAA"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { ConfirmPassword } from '@payloadcms/ui/fields/ConfirmPassword';
|
|
3
|
+
import { HiddenInput } from '@payloadcms/ui/fields/HiddenInput';
|
|
4
|
+
import { Password } from '@payloadcms/ui/fields/Password';
|
|
5
|
+
import { Form, useFormFields } from '@payloadcms/ui/forms/Form';
|
|
6
|
+
import { FormSubmit } from '@payloadcms/ui/forms/Submit';
|
|
7
|
+
import { useAuth } from '@payloadcms/ui/providers/Auth';
|
|
8
|
+
import { useConfig } from '@payloadcms/ui/providers/Config';
|
|
9
|
+
import { useTranslation } from '@payloadcms/ui/providers/Translation';
|
|
10
|
+
import { useRouter } from 'next/navigation.js';
|
|
11
|
+
import React from 'react';
|
|
12
|
+
import { toast } from 'react-toastify';
|
|
13
|
+
const initialState = {
|
|
14
|
+
'confirm-password': {
|
|
15
|
+
initialValue: '',
|
|
16
|
+
valid: false,
|
|
17
|
+
value: ''
|
|
18
|
+
},
|
|
19
|
+
password: {
|
|
20
|
+
initialValue: '',
|
|
21
|
+
valid: false,
|
|
22
|
+
value: ''
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
export const ResetPasswordClient = ({ token })=>{
|
|
26
|
+
const i18n = useTranslation();
|
|
27
|
+
const { admin: { user: userSlug }, routes: { admin, api }, serverURL } = useConfig();
|
|
28
|
+
const history = useRouter();
|
|
29
|
+
const { fetchFullUser } = useAuth();
|
|
30
|
+
const onSuccess = React.useCallback(async (data)=>{
|
|
31
|
+
if (data.token) {
|
|
32
|
+
await fetchFullUser();
|
|
33
|
+
history.push(`${admin}`);
|
|
34
|
+
} else {
|
|
35
|
+
history.push(`${admin}/login`);
|
|
36
|
+
toast.success(i18n.t('general:updatedSuccessfully'), {
|
|
37
|
+
autoClose: 3000
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}, [
|
|
41
|
+
fetchFullUser,
|
|
42
|
+
history,
|
|
43
|
+
admin,
|
|
44
|
+
i18n
|
|
45
|
+
]);
|
|
46
|
+
return /*#__PURE__*/ React.createElement(Form, {
|
|
47
|
+
action: `${serverURL}${api}/${userSlug}/reset-password`,
|
|
48
|
+
initialState: initialState,
|
|
49
|
+
method: "POST",
|
|
50
|
+
onSuccess: onSuccess
|
|
51
|
+
}, /*#__PURE__*/ React.createElement(PasswordToConfirm, null), /*#__PURE__*/ React.createElement(ConfirmPassword, null), /*#__PURE__*/ React.createElement(HiddenInput, {
|
|
52
|
+
forceUsePathFromProps: true,
|
|
53
|
+
name: "token",
|
|
54
|
+
value: token
|
|
55
|
+
}), /*#__PURE__*/ React.createElement(FormSubmit, null, i18n.t('authentication:resetPassword')));
|
|
56
|
+
};
|
|
57
|
+
const PasswordToConfirm = ()=>{
|
|
58
|
+
const { t } = useTranslation();
|
|
59
|
+
const { value: confirmValue } = useFormFields(([fields])=>{
|
|
60
|
+
return fields['confirm-password'];
|
|
61
|
+
});
|
|
62
|
+
const validate = React.useCallback((value)=>{
|
|
63
|
+
if (!value) {
|
|
64
|
+
return t('validation:required');
|
|
65
|
+
}
|
|
66
|
+
if (value === confirmValue) {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
return t('fields:passwordsDoNotMatch');
|
|
70
|
+
}, [
|
|
71
|
+
confirmValue,
|
|
72
|
+
t
|
|
73
|
+
]);
|
|
74
|
+
return /*#__PURE__*/ React.createElement(Password, {
|
|
75
|
+
autoComplete: "off",
|
|
76
|
+
label: t('authentication:newPassword'),
|
|
77
|
+
name: "password",
|
|
78
|
+
required: true,
|
|
79
|
+
validate: validate
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
//# sourceMappingURL=index.client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/views/ResetPassword/index.client.tsx"],"sourcesContent":["'use client'\nimport type { FormState } from 'payload/types'\n\nimport { ConfirmPassword } from '@payloadcms/ui/fields/ConfirmPassword'\nimport { HiddenInput } from '@payloadcms/ui/fields/HiddenInput'\nimport { Password } from '@payloadcms/ui/fields/Password'\nimport { Form, useFormFields } from '@payloadcms/ui/forms/Form'\nimport { FormSubmit } from '@payloadcms/ui/forms/Submit'\nimport { useAuth } from '@payloadcms/ui/providers/Auth'\nimport { useConfig } from '@payloadcms/ui/providers/Config'\nimport { useTranslation } from '@payloadcms/ui/providers/Translation'\nimport { useRouter } from 'next/navigation.js'\nimport React from 'react'\nimport { toast } from 'react-toastify'\n\ntype Args = {\n token: string\n}\n\nconst initialState: FormState = {\n 'confirm-password': {\n initialValue: '',\n valid: false,\n value: '',\n },\n password: {\n initialValue: '',\n valid: false,\n value: '',\n },\n}\n\nexport const ResetPasswordClient: React.FC<Args> = ({ token }) => {\n const i18n = useTranslation()\n const {\n admin: { user: userSlug },\n routes: { admin, api },\n serverURL,\n } = useConfig()\n\n const history = useRouter()\n\n const { fetchFullUser } = useAuth()\n\n const onSuccess = React.useCallback(\n async (data) => {\n if (data.token) {\n await fetchFullUser()\n history.push(`${admin}`)\n } else {\n history.push(`${admin}/login`)\n toast.success(i18n.t('general:updatedSuccessfully'), { autoClose: 3000 })\n }\n },\n [fetchFullUser, history, admin, i18n],\n )\n\n return (\n <Form\n action={`${serverURL}${api}/${userSlug}/reset-password`}\n initialState={initialState}\n method=\"POST\"\n onSuccess={onSuccess}\n >\n <PasswordToConfirm />\n <ConfirmPassword />\n <HiddenInput forceUsePathFromProps name=\"token\" value={token} />\n <FormSubmit>{i18n.t('authentication:resetPassword')}</FormSubmit>\n </Form>\n )\n}\n\nconst PasswordToConfirm = () => {\n const { t } = useTranslation()\n const { value: confirmValue } = useFormFields(([fields]) => {\n return fields['confirm-password']\n })\n\n const validate = React.useCallback(\n (value: string) => {\n if (!value) {\n return t('validation:required')\n }\n\n if (value === confirmValue) {\n return true\n }\n\n return t('fields:passwordsDoNotMatch')\n },\n [confirmValue, t],\n )\n\n return (\n <Password\n autoComplete=\"off\"\n label={t('authentication:newPassword')}\n name=\"password\"\n required\n validate={validate}\n />\n )\n}\n"],"names":["ConfirmPassword","HiddenInput","Password","Form","useFormFields","FormSubmit","useAuth","useConfig","useTranslation","useRouter","React","toast","initialState","initialValue","valid","value","password","ResetPasswordClient","token","i18n","admin","user","userSlug","routes","api","serverURL","history","fetchFullUser","onSuccess","useCallback","data","push","success","t","autoClose","action","method","PasswordToConfirm","forceUsePathFromProps","name","confirmValue","fields","validate","autoComplete","label","required"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;AAGA,SAASA,eAAe,QAAQ,wCAAuC;AACvE,SAASC,WAAW,QAAQ,oCAAmC;AAC/D,SAASC,QAAQ,QAAQ,iCAAgC;AACzD,SAASC,IAAI,EAAEC,aAAa,QAAQ,4BAA2B;AAC/D,SAASC,UAAU,QAAQ,8BAA6B;AACxD,SAASC,OAAO,QAAQ,gCAA+B;AACvD,SAASC,SAAS,QAAQ,kCAAiC;AAC3D,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,SAAS,QAAQ,qBAAoB;AAC9C,OAAOC,WAAW,QAAO;AACzB,SAASC,KAAK,QAAQ,iBAAgB;AAMtC,MAAMC,eAA0B;IAC9B,oBAAoB;QAClBC,cAAc;QACdC,OAAO;QACPC,OAAO;IACT;IACAC,UAAU;QACRH,cAAc;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ACT;QAEA,OAAOP,EAAE;IACX,GACA;QAACO;QAAcP;KAAE;IAGnB,qBACE,oBAAC/B;QACCyC,cAAa;QACbC,OAAOX,EAAE;QACTM,MAAK;QACLM,UAAAA;QACAH,UAAUA;;AAGhB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/views/ResetPassword/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/views/ResetPassword/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAMnD,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,cAAc,CAAA;AAErB,eAAO,MAAM,sBAAsB,mBAAmB,CAAA;AAItD,OAAO,EAAE,6BAA6B,EAAE,MAAM,WAAW,CAAA;AAEzD,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAgDlD,CAAA"}
|
|
@@ -1,30 +1,17 @@
|
|
|
1
1
|
import { Button } from '@payloadcms/ui/elements/Button';
|
|
2
2
|
import { Translation } from '@payloadcms/ui/elements/Translation';
|
|
3
|
-
import { ConfirmPassword } from '@payloadcms/ui/fields/ConfirmPassword';
|
|
4
|
-
import { HiddenInput } from '@payloadcms/ui/fields/HiddenInput';
|
|
5
|
-
import { Password } from '@payloadcms/ui/fields/Password';
|
|
6
|
-
import { Form } from '@payloadcms/ui/forms/Form';
|
|
7
|
-
import { FormSubmit } from '@payloadcms/ui/forms/Submit';
|
|
8
3
|
import { MinimalTemplate } from '@payloadcms/ui/templates/Minimal';
|
|
9
4
|
import LinkImport from 'next/link.js';
|
|
10
5
|
import React from 'react';
|
|
6
|
+
import { ResetPasswordClient } from './index.client.js';
|
|
11
7
|
export const resetPasswordBaseClass = 'reset-password';
|
|
12
8
|
const Link = LinkImport.default || LinkImport;
|
|
13
9
|
export { generateResetPasswordMetadata } from './meta.js';
|
|
14
10
|
export const ResetPassword = ({ initPageResult, params })=>{
|
|
15
11
|
const { req } = initPageResult;
|
|
16
|
-
const { token } = params;
|
|
12
|
+
const { segments: [_, token] } = params;
|
|
17
13
|
const { i18n, payload: { config }, user } = req;
|
|
18
|
-
const {
|
|
19
|
-
// const onSuccess = async (data) => {
|
|
20
|
-
// if (data.token) {
|
|
21
|
-
// await fetchFullUser()
|
|
22
|
-
// history.push(`${admin}`)
|
|
23
|
-
// } else {
|
|
24
|
-
// history.push(`${admin}/login`)
|
|
25
|
-
// toast.success(i18n.t('general:updatedSuccessfully'), { autoClose: 3000 })
|
|
26
|
-
// }
|
|
27
|
-
// }
|
|
14
|
+
const { routes: { admin } } = config;
|
|
28
15
|
if (user) {
|
|
29
16
|
return /*#__PURE__*/ React.createElement(MinimalTemplate, {
|
|
30
17
|
className: resetPasswordBaseClass
|
|
@@ -49,21 +36,9 @@ export const ResetPassword = ({ initPageResult, params })=>{
|
|
|
49
36
|
className: resetPasswordBaseClass
|
|
50
37
|
}, /*#__PURE__*/ React.createElement("div", {
|
|
51
38
|
className: `${resetPasswordBaseClass}__wrap`
|
|
52
|
-
}, /*#__PURE__*/ React.createElement("h1", null, i18n.t('authentication:resetPassword')), /*#__PURE__*/ React.createElement(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
// onSuccess={onSuccess}
|
|
56
|
-
redirect: admin
|
|
57
|
-
}, /*#__PURE__*/ React.createElement(Password, {
|
|
58
|
-
autoComplete: "off",
|
|
59
|
-
label: i18n.t('authentication:newPassword'),
|
|
60
|
-
name: "password",
|
|
61
|
-
required: true
|
|
62
|
-
}), /*#__PURE__*/ React.createElement(ConfirmPassword, null), /*#__PURE__*/ React.createElement(HiddenInput, {
|
|
63
|
-
forceUsePathFromProps: true,
|
|
64
|
-
name: "token",
|
|
65
|
-
value: token
|
|
66
|
-
}), /*#__PURE__*/ React.createElement(FormSubmit, null, i18n.t('authentication:resetPassword')))));
|
|
39
|
+
}, /*#__PURE__*/ React.createElement("h1", null, i18n.t('authentication:resetPassword')), /*#__PURE__*/ React.createElement(ResetPasswordClient, {
|
|
40
|
+
token: token
|
|
41
|
+
})));
|
|
67
42
|
};
|
|
68
43
|
|
|
69
44
|
//# sourceMappingURL=index.js.map
|