@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,"sources":["../../../src/views/ResetPassword/index.tsx"],"sourcesContent":["import type { AdminViewProps } from 'payload/types'\n\nimport { Button } from '@payloadcms/ui/elements/Button'\nimport { Translation } from '@payloadcms/ui/elements/Translation'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/views/ResetPassword/index.tsx"],"sourcesContent":["import type { AdminViewProps } from 'payload/types'\n\nimport { Button } from '@payloadcms/ui/elements/Button'\nimport { Translation } from '@payloadcms/ui/elements/Translation'\nimport { MinimalTemplate } from '@payloadcms/ui/templates/Minimal'\nimport LinkImport from 'next/link.js'\nimport React from 'react'\n\nimport { ResetPasswordClient } from './index.client.js'\nimport './index.scss'\n\nexport const resetPasswordBaseClass = 'reset-password'\n\nconst Link = (LinkImport.default || LinkImport) as unknown as typeof LinkImport.default\n\nexport { generateResetPasswordMetadata } from './meta.js'\n\nexport const ResetPassword: React.FC<AdminViewProps> = ({ initPageResult, params }) => {\n const { req } = initPageResult\n\n const {\n segments: [_, token],\n } = params\n\n const {\n i18n,\n payload: { config },\n user,\n } = req\n\n const {\n routes: { admin },\n } = config\n\n if (user) {\n return (\n <MinimalTemplate className={resetPasswordBaseClass}>\n <div className={`${resetPasswordBaseClass}__wrap`}>\n <h1>{i18n.t('authentication:alreadyLoggedIn')}</h1>\n <p>\n <Translation\n elements={{\n '0': ({ children }) => <Link href={`${admin}/account`}>{children}</Link>,\n }}\n i18nKey=\"authentication:loggedInChangePassword\"\n t={i18n.t}\n />\n </p>\n <br />\n <Button Link={Link} buttonStyle=\"secondary\" el=\"link\" to={admin}>\n {i18n.t('general:backToDashboard')}\n </Button>\n </div>\n </MinimalTemplate>\n )\n }\n\n return (\n <MinimalTemplate className={resetPasswordBaseClass}>\n <div className={`${resetPasswordBaseClass}__wrap`}>\n <h1>{i18n.t('authentication:resetPassword')}</h1>\n <ResetPasswordClient token={token} />\n </div>\n </MinimalTemplate>\n )\n}\n"],"names":["Button","Translation","MinimalTemplate","LinkImport","React","ResetPasswordClient","resetPasswordBaseClass","Link","default","generateResetPasswordMetadata","ResetPassword","initPageResult","params","req","segments","_","token","i18n","payload","config","user","routes","admin","className","div","h1","t","p","elements","children","href","i18nKey","br","buttonStyle","el","to"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,MAAM,QAAQ,iCAAgC;AACvD,SAASC,WAAW,QAAQ,sCAAqC;AACjE,SAASC,eAAe,QAAQ,mCAAkC;AAClE,OAAOC,gBAAgB,eAAc;AACrC,OAAOC,WAAW,QAAO;AAEzB,SAASC,mBAAmB,QAAQ,oBAAmB;AAGvD,OAAO,MAAMC,yBAAyB,iBAAgB;AAEtD,MAAMC,OAAQJ,WAAWK,OAAO,IAAIL;AAEpC,SAASM,6BAA6B,QAAQ,YAAW;AAEzD,OAAO,MAAMC,gBAA0C,CAAC,EAAEC,cAAc,EAAEC,MAAM,EAAE;IAChF,MAAM,EAAEC,GAAG,EAAE,GAAGF;IAEhB,MAAM,EACJG,UAAU,CAACC,GAAGC,MAAM,EACrB,GAAGJ;IAEJ,MAAM,EACJK,IAAI,EACJC,SAAS,EAAEC,MAAM,EAAE,EACnBC,IAAI,EACL,GAAGP;IAEJ,MAAM,EACJQ,QAAQ,EAAEC,KAAK,EAAE,EAClB,GAAGH;IAEJ,IAAIC,MAAM;QACR,qBACE,oBAAClB;YAAgBqB,WAAWjB;yBAC1B,oBAACkB;YAAID,WAAW,CAAC,EAAEjB,uBAAuB,MAAM,CAAC;yBAC/C,oBAACmB,YAAIR,KAAKS,CAAC,CAAC,kDACZ,oBAACC,yBACC,oBAAC1B;YACC2B,UAAU;gBACR,KAAK,CAAC,EAAEC,QAAQ,EAAE,iBAAK,oBAACtB;wBAAKuB,MAAM,CAAC,EAAER,MAAM,QAAQ,CAAC;uBAAGO;YAC1D;YACAE,SAAQ;YACRL,GAAGT,KAAKS,CAAC;2BAGb,oBAACM,2BACD,oBAAChC;YAAOO,MAAMA;YAAM0B,aAAY;YAAYC,IAAG;YAAOC,IAAIb;WACvDL,KAAKS,CAAC,CAAC;IAKlB;IAEA,qBACE,oBAACxB;QAAgBqB,WAAWjB;qBAC1B,oBAACkB;QAAID,WAAW,CAAC,EAAEjB,uBAAuB,MAAM,CAAC;qBAC/C,oBAACmB,YAAIR,KAAKS,CAAC,CAAC,gDACZ,oBAACrB;QAAoBW,OAAOA;;AAIpC,EAAC"}
|
|
@@ -1,15 +1,5 @@
|
|
|
1
1
|
.reset-password {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
flex-wrap: wrap;
|
|
5
|
-
min-height: 100vh;
|
|
6
|
-
|
|
7
|
-
&__wrap {
|
|
8
|
-
margin: 0 auto var(--base);
|
|
9
|
-
width: 100%;
|
|
10
|
-
|
|
11
|
-
svg {
|
|
12
|
-
width: 100%;
|
|
13
|
-
}
|
|
2
|
+
form > .field-type {
|
|
3
|
+
margin-bottom: var(--base);
|
|
14
4
|
}
|
|
15
5
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SanitizedConfig } from 'payload/config';
|
|
2
2
|
import type { AdminViewComponent } from 'payload/types';
|
|
3
|
-
import type { initPage } from '../../utilities/initPage.js';
|
|
3
|
+
import type { initPage } from '../../utilities/initPage/index.js';
|
|
4
4
|
export declare const getViewFromConfig: ({ adminRoute, config, currentRoute, searchParams, segments, }: {
|
|
5
5
|
adminRoute;
|
|
6
6
|
config: SanitizedConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getViewFromConfig.d.ts","sourceRoot":"","sources":["../../../src/views/Root/getViewFromConfig.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACrD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAEvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"getViewFromConfig.d.ts","sourceRoot":"","sources":["../../../src/views/Root/getViewFromConfig.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACrD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAEvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAA;AA+BjE,eAAO,MAAM,iBAAiB,kEAM3B;IACD,UAAU,CAAA;IACV,MAAM,EAAE,eAAe,CAAA;IACvB,YAAY,EAAE,MAAM,CAAA;IACpB,YAAY,EAAE;QACZ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAA;KACjC,CAAA;IACD,QAAQ,EAAE,MAAM,EAAE,CAAA;CACnB,KAAG;IACF,WAAW,EAAE,kBAAkB,CAAA;IAC/B,eAAe,EAAE,WAAW,eAAe,CAAC,CAAC,CAAC,CAAC,CAAA;IAC/C,iBAAiB,EAAE,MAAM,CAAA;IACzB,YAAY,EAAE,SAAS,GAAG,SAAS,CAAA;CA+GpC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/views/Root/getViewFromConfig.tsx"],"sourcesContent":["import type { SanitizedConfig } from 'payload/config'\nimport type { AdminViewComponent } from 'payload/types'\n\nimport type { initPage } from '../../utilities/initPage.js'\n\nimport { Account } from '../Account/index.js'\nimport { CreateFirstUserView } from '../CreateFirstUser/index.js'\nimport { Dashboard } from '../Dashboard/index.js'\nimport { Document as DocumentView } from '../Document/index.js'\nimport { ForgotPasswordView, forgotPasswordBaseClass } from '../ForgotPassword/index.js'\nimport { ListView } from '../List/index.js'\nimport { LoginView, loginBaseClass } from '../Login/index.js'\nimport { LogoutInactivity, LogoutView } from '../Logout/index.js'\nimport { ResetPassword, resetPasswordBaseClass } from '../ResetPassword/index.js'\nimport { UnauthorizedView } from '../Unauthorized/index.js'\nimport { Verify, verifyBaseClass } from '../Verify/index.js'\nimport { getCustomViewByRoute } from './getCustomViewByRoute.js'\n\nconst baseClasses = {\n forgot: forgotPasswordBaseClass,\n login: loginBaseClass,\n reset: resetPasswordBaseClass,\n verify: verifyBaseClass,\n}\n\nconst oneSegmentViews = {\n 'create-first-user': CreateFirstUserView,\n forgot: ForgotPasswordView,\n login: LoginView,\n logout: LogoutView,\n 'logout-inactivity': LogoutInactivity,\n unauthorized: UnauthorizedView,\n}\n\nexport const getViewFromConfig = ({\n adminRoute,\n config,\n currentRoute,\n searchParams,\n segments,\n}: {\n adminRoute\n config: SanitizedConfig\n currentRoute: string\n searchParams: {\n [key: string]: string | string[]\n }\n segments: string[]\n}): {\n DefaultView: AdminViewComponent\n initPageOptions: Parameters<typeof initPage>[0]\n templateClassName: string\n templateType: 'default' | 'minimal'\n} => {\n let ViewToRender: AdminViewComponent = null\n let templateClassName: string\n let templateType: 'default' | 'minimal' = 'minimal'\n\n const initPageOptions: Parameters<typeof initPage>[0] = {\n config,\n route: currentRoute,\n searchParams,\n }\n\n const [segmentOne, segmentTwo] = segments\n\n const isGlobal = segmentOne === 'globals'\n const isCollection = segmentOne === 'collections'\n\n switch (segments.length) {\n case 0: {\n if (currentRoute === adminRoute) {\n ViewToRender = Dashboard\n templateClassName = 'dashboard'\n templateType = 'default'\n initPageOptions.redirectUnauthenticatedUser = true\n }\n break\n }\n case 1: {\n if (oneSegmentViews[segmentOne] && segmentOne !== 'account') {\n // --> /create-first-user\n // --> /forgot\n // --> /login\n // --> /logout\n // --> /logout-inactivity\n // --> /unauthorized\n ViewToRender = oneSegmentViews[segmentOne]\n templateClassName = baseClasses[segmentOne]\n templateType = 'minimal'\n } else if (segmentOne === 'account') {\n // --> /account\n initPageOptions.redirectUnauthenticatedUser = true\n ViewToRender = Account\n templateClassName = 'account'\n templateType = 'default'\n }\n break\n }\n case 2: {\n if (segmentOne === 'reset') {\n // --> /reset/:token\n ViewToRender = ResetPassword\n templateClassName = baseClasses[segmentTwo]\n templateType = 'minimal'\n }\n\n if (isCollection) {\n // --> /collections/:collectionSlug\n initPageOptions.redirectUnauthenticatedUser = true\n ViewToRender = ListView\n templateClassName = `${segmentTwo}-list`\n templateType = 'default'\n } else if (isGlobal) {\n // --> /globals/:globalSlug\n initPageOptions.redirectUnauthenticatedUser = true\n ViewToRender = DocumentView\n templateClassName = 'global-edit'\n templateType = 'default'\n }\n break\n }\n default:\n if (segmentTwo === 'verify') {\n // --> /:collectionSlug/verify/:token\n ViewToRender = Verify\n templateClassName = 'verify'\n templateType = 'minimal'\n } else if (isCollection) {\n // Custom Views\n // --> /collections/:collectionSlug/:id\n // --> /collections/:collectionSlug/:id/preview\n // --> /collections/:collectionSlug/:id/versions\n // --> /collections/:collectionSlug/:id/versions/:versionId\n // --> /collections/:collectionSlug/:id/api\n initPageOptions.redirectUnauthenticatedUser = true\n ViewToRender = DocumentView\n templateClassName = `collection-default-edit`\n templateType = 'default'\n } else if (isGlobal) {\n // Custom Views\n // --> /globals/:globalSlug/versions\n // --> /globals/:globalSlug/preview\n // --> /globals/:globalSlug/versions/:versionId\n // --> /globals/:globalSlug/api\n initPageOptions.redirectUnauthenticatedUser = true\n ViewToRender = DocumentView\n templateClassName = `global-edit`\n templateType = 'default'\n }\n break\n }\n\n if (!ViewToRender) {\n ViewToRender = getCustomViewByRoute({ config, currentRoute })\n }\n\n return {\n DefaultView: ViewToRender,\n initPageOptions,\n templateClassName,\n templateType,\n }\n}\n"],"names":["Account","CreateFirstUserView","Dashboard","Document","DocumentView","ForgotPasswordView","forgotPasswordBaseClass","ListView","LoginView","loginBaseClass","LogoutInactivity","LogoutView","ResetPassword","resetPasswordBaseClass","UnauthorizedView","Verify","verifyBaseClass","getCustomViewByRoute","baseClasses","forgot","login","reset","verify","oneSegmentViews","logout","unauthorized","getViewFromConfig","adminRoute","config","currentRoute","searchParams","segments","ViewToRender","templateClassName","templateType","initPageOptions","route","segmentOne","segmentTwo","isGlobal","isCollection","length","redirectUnauthenticatedUser","DefaultView"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAKA,SAASA,OAAO,QAAQ,sBAAqB;AAC7C,SAASC,mBAAmB,QAAQ,8BAA6B;AACjE,SAASC,SAAS,QAAQ,wBAAuB;AACjD,SAASC,YAAYC,YAAY,QAAQ,uBAAsB;AAC/D,SAASC,kBAAkB,EAAEC,uBAAuB,QAAQ,6BAA4B;AACxF,SAASC,QAAQ,QAAQ,mBAAkB;AAC3C,SAASC,SAAS,EAAEC,cAAc,QAAQ,oBAAmB;AAC7D,SAASC,gBAAgB,EAAEC,UAAU,QAAQ,qBAAoB;AACjE,SAASC,aAAa,EAAEC,sBAAsB,QAAQ,4BAA2B;AACjF,SAASC,gBAAgB,QAAQ,2BAA0B;AAC3D,SAASC,MAAM,EAAEC,eAAe,QAAQ,qBAAoB;AAC5D,SAASC,oBAAoB,QAAQ,4BAA2B;AAEhE,MAAMC,cAAc;IAClBC,QAAQb;IACRc,OAAOX;IACPY,OAAOR;IACPS,QAAQN;AACV;AAEA,MAAMO,kBAAkB;IACtB,qBAAqBtB;IACrBkB,QAAQd;IACRe,OAAOZ;IACPgB,QAA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3BJ,gBAAgBO,2BAA2B,GAAG;oBAC9CV,eAAe5B;oBACf6B,oBAAoB;oBACpBC,eAAe;gBACjB;gBACA;YACF;QACA;YACE,IAAII,eAAe,UAAU;gBAC3B,qCAAqC;gBACrCN,eAAejB;gBACfkB,oBAAoB;gBACpBC,eAAe;YACjB,OAAO,IAAIM,cAAc;gBACvB,eAAe;gBACf,uCAAuC;gBACvC,+CAA+C;gBAC/C,gDAAgD;gBAChD,2DAA2D;gBAC3D,2CAA2C;gBAC3CL,gBAAgBO,2BAA2B,GAAG;gBAC9CV,eAAe5B;gBACf6B,oBAAoB,CAAC,uBAAuB,CAAC;gBAC7CC,eAAe;YACjB,OAAO,IAAIK,UAAU;gBACnB,eAAe;gBACf,oCAAoC;gBACpC,mCAAmC;gBACnC,+CAA+C;gBAC/C,+BAA+B;gBAC/BJ,gBAAgBO,2BAA2B,GAAG;gBAC9CV,eAAe5B;gBACf6B,oBAAoB,CAAC,WAAW,CAAC;gBACjCC,eAAe;YACjB;YACA;IACJ;IAEA,IAAI,CAACF,cAAc;QACjBA,eAAef,qBAAqB;YAAEW;YAAQC;QAAa;IAC7D;IAEA,OAAO;QACLc,aAAaX;QACbG;QACAF;QACAC;IACF;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/views/Root/getViewFromConfig.tsx"],"sourcesContent":["import type { SanitizedConfig } from 'payload/config'\nimport type { AdminViewComponent } from 'payload/types'\n\nimport type { initPage } from '../../utilities/initPage/index.js'\n\nimport { Account } from '../Account/index.js'\nimport { CreateFirstUserView } from '../CreateFirstUser/index.js'\nimport { Dashboard } from '../Dashboard/index.js'\nimport { Document as DocumentView } from '../Document/index.js'\nimport { ForgotPasswordView, forgotPasswordBaseClass } from '../ForgotPassword/index.js'\nimport { ListView } from '../List/index.js'\nimport { LoginView, loginBaseClass } from '../Login/index.js'\nimport { LogoutInactivity, LogoutView } from '../Logout/index.js'\nimport { ResetPassword, resetPasswordBaseClass } from '../ResetPassword/index.js'\nimport { UnauthorizedView } from '../Unauthorized/index.js'\nimport { Verify, verifyBaseClass } from '../Verify/index.js'\nimport { getCustomViewByRoute } from './getCustomViewByRoute.js'\n\nconst baseClasses = {\n forgot: forgotPasswordBaseClass,\n login: loginBaseClass,\n reset: resetPasswordBaseClass,\n verify: verifyBaseClass,\n}\n\nconst oneSegmentViews = {\n 'create-first-user': CreateFirstUserView,\n forgot: ForgotPasswordView,\n login: LoginView,\n logout: LogoutView,\n 'logout-inactivity': LogoutInactivity,\n unauthorized: UnauthorizedView,\n}\n\nexport const getViewFromConfig = ({\n adminRoute,\n config,\n currentRoute,\n searchParams,\n segments,\n}: {\n adminRoute\n config: SanitizedConfig\n currentRoute: string\n searchParams: {\n [key: string]: string | string[]\n }\n segments: string[]\n}): {\n DefaultView: AdminViewComponent\n initPageOptions: Parameters<typeof initPage>[0]\n templateClassName: string\n templateType: 'default' | 'minimal'\n} => {\n let ViewToRender: AdminViewComponent = null\n let templateClassName: string\n let templateType: 'default' | 'minimal' = 'minimal'\n\n const initPageOptions: Parameters<typeof initPage>[0] = {\n config,\n route: currentRoute,\n searchParams,\n }\n\n const [segmentOne, segmentTwo] = segments\n\n const isGlobal = segmentOne === 'globals'\n const isCollection = segmentOne === 'collections'\n\n switch (segments.length) {\n case 0: {\n if (currentRoute === adminRoute) {\n ViewToRender = Dashboard\n templateClassName = 'dashboard'\n templateType = 'default'\n initPageOptions.redirectUnauthenticatedUser = true\n }\n break\n }\n case 1: {\n if (oneSegmentViews[segmentOne] && segmentOne !== 'account') {\n // --> /create-first-user\n // --> /forgot\n // --> /login\n // --> /logout\n // --> /logout-inactivity\n // --> /unauthorized\n ViewToRender = oneSegmentViews[segmentOne]\n templateClassName = baseClasses[segmentOne]\n templateType = 'minimal'\n } else if (segmentOne === 'account') {\n // --> /account\n initPageOptions.redirectUnauthenticatedUser = true\n ViewToRender = Account\n templateClassName = 'account'\n templateType = 'default'\n }\n break\n }\n case 2: {\n if (segmentOne === 'reset') {\n // --> /reset/:token\n ViewToRender = ResetPassword\n templateClassName = baseClasses[segmentTwo]\n templateType = 'minimal'\n }\n\n if (isCollection) {\n // --> /collections/:collectionSlug\n initPageOptions.redirectUnauthenticatedUser = true\n ViewToRender = ListView\n templateClassName = `${segmentTwo}-list`\n templateType = 'default'\n } else if (isGlobal) {\n // --> /globals/:globalSlug\n initPageOptions.redirectUnauthenticatedUser = true\n ViewToRender = DocumentView\n templateClassName = 'global-edit'\n templateType = 'default'\n }\n break\n }\n default:\n if (segmentTwo === 'verify') {\n // --> /:collectionSlug/verify/:token\n ViewToRender = Verify\n templateClassName = 'verify'\n templateType = 'minimal'\n } else if (isCollection) {\n // Custom Views\n // --> /collections/:collectionSlug/:id\n // --> /collections/:collectionSlug/:id/preview\n // --> /collections/:collectionSlug/:id/versions\n // --> /collections/:collectionSlug/:id/versions/:versionId\n // --> /collections/:collectionSlug/:id/api\n initPageOptions.redirectUnauthenticatedUser = true\n ViewToRender = DocumentView\n templateClassName = `collection-default-edit`\n templateType = 'default'\n } else if (isGlobal) {\n // Custom Views\n // --> /globals/:globalSlug/versions\n // --> /globals/:globalSlug/preview\n // --> /globals/:globalSlug/versions/:versionId\n // --> /globals/:globalSlug/api\n initPageOptions.redirectUnauthenticatedUser = true\n ViewToRender = DocumentView\n templateClassName = `global-edit`\n templateType = 'default'\n }\n break\n }\n\n if (!ViewToRender) {\n ViewToRender = getCustomViewByRoute({ config, currentRoute })\n }\n\n return {\n DefaultView: ViewToRender,\n initPageOptions,\n templateClassName,\n templateType,\n }\n}\n"],"names":["Account","CreateFirstUserView","Dashboard","Document","DocumentView","ForgotPasswordView","forgotPasswordBaseClass","ListView","LoginView","loginBaseClass","LogoutInactivity","LogoutView","ResetPassword","resetPasswordBaseClass","UnauthorizedView","Verify","verifyBaseClass","getCustomViewByRoute","baseClasses","forgot","login","reset","verify","oneSegmentViews","logout","unauthorized","getViewFromConfig","adminRoute","config","currentRoute","searchParams","segments","ViewToRender","templateClassName","templateType","initPageOptions","route","segmentOne","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BAC9CV,eAAe5B;gBACf6B,oBAAoB,CAAC,uBAAuB,CAAC;gBAC7CC,eAAe;YACjB,OAAO,IAAIK,UAAU;gBACnB,eAAe;gBACf,oCAAoC;gBACpC,mCAAmC;gBACnC,+CAA+C;gBAC/C,+BAA+B;gBAC/BJ,gBAAgBO,2BAA2B,GAAG;gBAC9CV,eAAe5B;gBACf6B,oBAAoB,CAAC,WAAW,CAAC;gBACjCC,eAAe;YACjB;YACA;IACJ;IAEA,IAAI,CAACF,cAAc;QACjBA,eAAef,qBAAqB;YAAEW;YAAQC;QAAa;IAC7D;IAEA,OAAO;QACLc,aAAaX;QACbG;QACAF;QACAC;IACF;AACF,EAAC"}
|
package/dist/views/Root/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { DefaultTemplate } from '@payloadcms/ui/templates/Default';
|
|
|
2
2
|
import { MinimalTemplate } from '@payloadcms/ui/templates/Minimal';
|
|
3
3
|
import { notFound, redirect } from 'next/navigation.js';
|
|
4
4
|
import React, { Fragment } from 'react';
|
|
5
|
-
import { initPage } from '../../utilities/initPage.js';
|
|
5
|
+
import { initPage } from '../../utilities/initPage/index.js';
|
|
6
6
|
import { getViewFromConfig } from './getViewFromConfig.js';
|
|
7
7
|
export { generatePageMetadata } from './meta.js';
|
|
8
8
|
export const RootPage = async ({ config: configPromise, params, searchParams })=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/views/Root/index.tsx"],"sourcesContent":["import type { I18n } from '@payloadcms/translations'\nimport type { Metadata } from 'next'\nimport type { SanitizedConfig } from 'payload/types'\n\nimport { DefaultTemplate } from '@payloadcms/ui/templates/Default'\nimport { MinimalTemplate } from '@payloadcms/ui/templates/Minimal'\nimport { notFound, redirect } from 'next/navigation.js'\nimport React, { Fragment } from 'react'\n\nimport { initPage } from '../../utilities/initPage.js'\nimport { getViewFromConfig } from './getViewFromConfig.js'\n\nexport { generatePageMetadata } from './meta.js'\n\nexport type GenerateViewMetadata = (args: {\n config: SanitizedConfig\n i18n: I18n\n params?: { [key: string]: string | string[] }\n}) => Promise<Metadata>\n\nexport const RootPage = async ({\n config: configPromise,\n params,\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\n const {\n admin: { user: userSlug },\n routes: { admin: adminRoute },\n } = config\n\n const currentRoute = `${adminRoute}${Array.isArray(params.segments) ? `/${params.segments.join('/')}` : ''}`\n\n const segments = Array.isArray(params.segments) ? params.segments : []\n\n const { DefaultView, initPageOptions, templateClassName, templateType } = getViewFromConfig({\n adminRoute,\n config,\n currentRoute,\n searchParams,\n segments,\n })\n\n let dbHasUser = false\n\n if (!DefaultView) {\n notFound()\n }\n\n const initPageResult = await initPage(initPageOptions)\n\n if (initPageResult) {\n dbHasUser = await initPageResult?.req.payload.db\n .findOne({\n collection: userSlug,\n req: initPageResult?.req,\n })\n ?.then((doc) => !!doc)\n\n const createFirstUserRoute = `${adminRoute}/create-first-user`\n\n if (!dbHasUser && currentRoute !== createFirstUserRoute) {\n redirect(createFirstUserRoute)\n }\n\n if (dbHasUser && currentRoute === createFirstUserRoute) {\n redirect(adminRoute)\n }\n }\n\n const RenderedView = (\n <DefaultView initPageResult={initPageResult} params={params} searchParams={searchParams} />\n )\n\n return (\n <Fragment>\n {templateType === 'minimal' && (\n <MinimalTemplate className={templateClassName}>{RenderedView}</MinimalTemplate>\n )}\n {templateType === 'default' && (\n <DefaultTemplate config={config} visibleEntities={initPageResult.visibleEntities}>\n {RenderedView}\n </DefaultTemplate>\n )}\n </Fragment>\n )\n}\n"],"names":["DefaultTemplate","MinimalTemplate","notFound","redirect","React","Fragment","initPage","getViewFromConfig","generatePageMetadata","RootPage","config","configPromise","params","searchParams","admin","user","userSlug","routes","adminRoute","currentRoute","Array","isArray","segments","join","DefaultView","initPageOptions","templateClassName","templateType","dbHasUser","initPageResult","req","payload","db","findOne","collection","then","doc","createFirstUserRoute","RenderedView","className","visibleEntities"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,eAAe,QAAQ,mCAAkC;AAClE,SAASC,eAAe,QAAQ,mCAAkC;AAClE,SAASC,QAAQ,EAAEC,QAAQ,QAAQ,qBAAoB;AACvD,OAAOC,SAASC,QAAQ,QAAQ,QAAO;AAEvC,SAASC,QAAQ,QAAQ,
|
|
1
|
+
{"version":3,"sources":["../../../src/views/Root/index.tsx"],"sourcesContent":["import type { I18n } from '@payloadcms/translations'\nimport type { Metadata } from 'next'\nimport type { SanitizedConfig } from 'payload/types'\n\nimport { DefaultTemplate } from '@payloadcms/ui/templates/Default'\nimport { MinimalTemplate } from '@payloadcms/ui/templates/Minimal'\nimport { notFound, redirect } from 'next/navigation.js'\nimport React, { Fragment } from 'react'\n\nimport { initPage } from '../../utilities/initPage/index.js'\nimport { getViewFromConfig } from './getViewFromConfig.js'\n\nexport { generatePageMetadata } from './meta.js'\n\nexport type GenerateViewMetadata = (args: {\n config: SanitizedConfig\n i18n: I18n\n params?: { [key: string]: string | string[] }\n}) => Promise<Metadata>\n\nexport const RootPage = async ({\n config: configPromise,\n params,\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\n const {\n admin: { user: userSlug },\n routes: { admin: adminRoute },\n } = config\n\n const currentRoute = `${adminRoute}${Array.isArray(params.segments) ? `/${params.segments.join('/')}` : ''}`\n\n const segments = Array.isArray(params.segments) ? params.segments : []\n\n const { DefaultView, initPageOptions, templateClassName, templateType } = getViewFromConfig({\n adminRoute,\n config,\n currentRoute,\n searchParams,\n segments,\n })\n\n let dbHasUser = false\n\n if (!DefaultView) {\n notFound()\n }\n\n const initPageResult = await initPage(initPageOptions)\n\n if (initPageResult) {\n dbHasUser = await initPageResult?.req.payload.db\n .findOne({\n collection: userSlug,\n req: initPageResult?.req,\n })\n ?.then((doc) => !!doc)\n\n const createFirstUserRoute = `${adminRoute}/create-first-user`\n\n if (!dbHasUser && currentRoute !== createFirstUserRoute) {\n redirect(createFirstUserRoute)\n }\n\n if (dbHasUser && currentRoute === createFirstUserRoute) {\n redirect(adminRoute)\n }\n }\n\n const RenderedView = (\n <DefaultView initPageResult={initPageResult} params={params} searchParams={searchParams} />\n )\n\n return (\n <Fragment>\n {templateType === 'minimal' && (\n <MinimalTemplate className={templateClassName}>{RenderedView}</MinimalTemplate>\n )}\n {templateType === 'default' && (\n <DefaultTemplate config={config} visibleEntities={initPageResult.visibleEntities}>\n {RenderedView}\n </DefaultTemplate>\n )}\n </Fragment>\n )\n}\n"],"names":["DefaultTemplate","MinimalTemplate","notFound","redirect","React","Fragment","initPage","getViewFromConfig","generatePageMetadata","RootPage","config","configPromise","params","searchParams","admin","user","userSlug","routes","adminRoute","currentRoute","Array","isArray","segments","join","DefaultView","initPageOptions","templateClassName","templateType","dbHasUser","initPageResult","req","payload","db","findOne","collection","then","doc","createFirstUserRoute","RenderedView","className","visibleEntities"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,eAAe,QAAQ,mCAAkC;AAClE,SAASC,eAAe,QAAQ,mCAAkC;AAClE,SAASC,QAAQ,EAAEC,QAAQ,QAAQ,qBAAoB;AACvD,OAAOC,SAASC,QAAQ,QAAQ,QAAO;AAEvC,SAASC,QAAQ,QAAQ,oCAAmC;AAC5D,SAASC,iBAAiB,QAAQ,yBAAwB;AAE1D,SAASC,oBAAoB,QAAQ,YAAW;AAQhD,OAAO,MAAMC,WAAW,OAAO,EAC7BC,QAAQC,aAAa,EACrBC,MAAM,EACNC,YAAY,EASb;IACC,MAAMH,SAAS,MAAMC;IAErB,MAAM,EACJG,OAAO,EAAEC,MAAMC,QAAQ,EAAE,EACzBC,QAAQ,EAAEH,OAAOI,UAAU,EAAE,EAC9B,GAAGR;IAE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24",
|
|
4
4
|
"homepage": "https://payloadcms.com",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
"react-toastify": "8.2.0",
|
|
45
45
|
"sass": "^1.71.1",
|
|
46
46
|
"ws": "^8.16.0",
|
|
47
|
-
"@payloadcms/
|
|
48
|
-
"@payloadcms/
|
|
49
|
-
"@payloadcms/
|
|
47
|
+
"@payloadcms/translations": "3.0.0-beta.24",
|
|
48
|
+
"@payloadcms/graphql": "3.0.0-beta.24",
|
|
49
|
+
"@payloadcms/ui": "3.0.0-beta.24"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@next/eslint-plugin-next": "^14.1.0",
|
|
@@ -64,13 +64,13 @@
|
|
|
64
64
|
"terser-webpack-plugin": "^5.3.10",
|
|
65
65
|
"webpack": "^5.78.0",
|
|
66
66
|
"webpack-cli": "^5.1.4",
|
|
67
|
-
"payload": "3.0.0-beta.
|
|
67
|
+
"payload": "3.0.0-beta.24",
|
|
68
68
|
"@payloadcms/eslint-config": "1.1.1"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
71
|
"graphql": "^16.8.1",
|
|
72
72
|
"next": "^14.3.0-canary.7",
|
|
73
|
-
"payload": "3.0.0-beta.
|
|
73
|
+
"payload": "3.0.0-beta.24"
|
|
74
74
|
},
|
|
75
75
|
"engines": {
|
|
76
76
|
"node": ">=18.20.2"
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { InitPageResult, SanitizedConfig } from 'payload/types';
|
|
2
|
-
type Args = {
|
|
3
|
-
config: Promise<SanitizedConfig> | SanitizedConfig;
|
|
4
|
-
redirectUnauthenticatedUser?: boolean;
|
|
5
|
-
route: string;
|
|
6
|
-
searchParams: {
|
|
7
|
-
[key: string]: string | string[] | undefined;
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
export declare const initPage: ({ config: configPromise, redirectUnauthenticatedUser, route, searchParams, }: Args) => Promise<InitPageResult>;
|
|
11
|
-
export {};
|
|
12
|
-
//# sourceMappingURL=initPage.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"initPage.d.ts","sourceRoot":"","sources":["../../src/utilities/initPage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EAGd,eAAe,EAGhB,MAAM,eAAe,CAAA;AAatB,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,CAAA;IAClD,2BAA2B,CAAC,EAAE,OAAO,CAAA;IACrC,KAAK,EAAE,MAAM,CAAA;IACb,YAAY,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAA;KAAE,CAAA;CAC/D,CAAA;AAYD,eAAO,MAAM,QAAQ,iFAKlB,IAAI,KAAG,QAAQ,cAAc,CA0G/B,CAAA"}
|
|
@@ -1,113 +0,0 @@
|
|
|
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 { notFound, redirect } from 'next/navigation.js';
|
|
5
|
-
import { parseCookies } from 'payload/auth';
|
|
6
|
-
import { createLocalReq, isEntityHidden } from 'payload/utilities';
|
|
7
|
-
import qs from 'qs';
|
|
8
|
-
import { getPayloadHMR } from '../utilities/getPayloadHMR.js';
|
|
9
|
-
import { getRequestLanguage } from './getRequestLanguage.js';
|
|
10
|
-
const authRoutes = [
|
|
11
|
-
'/login',
|
|
12
|
-
'/logout',
|
|
13
|
-
'/create-first-user',
|
|
14
|
-
'/forgot',
|
|
15
|
-
'/reset',
|
|
16
|
-
'/verify',
|
|
17
|
-
'/logout-inactivity'
|
|
18
|
-
];
|
|
19
|
-
export const initPage = async ({ config: configPromise, redirectUnauthenticatedUser = false, route, searchParams })=>{
|
|
20
|
-
const headers = getHeaders();
|
|
21
|
-
const localeParam = searchParams?.locale;
|
|
22
|
-
const payload = await getPayloadHMR({
|
|
23
|
-
config: configPromise
|
|
24
|
-
});
|
|
25
|
-
const { collections, globals, localization, routes } = payload.config;
|
|
26
|
-
const queryString = `${qs.stringify(searchParams ?? {}, {
|
|
27
|
-
addQueryPrefix: true
|
|
28
|
-
})}`;
|
|
29
|
-
const defaultLocale = localization && localization.defaultLocale ? localization.defaultLocale : 'en';
|
|
30
|
-
const localeCode = localeParam || defaultLocale;
|
|
31
|
-
const locale = localization && findLocaleFromCode(localization, localeCode);
|
|
32
|
-
const cookies = parseCookies(headers);
|
|
33
|
-
const language = getRequestLanguage({
|
|
34
|
-
config: payload.config,
|
|
35
|
-
cookies,
|
|
36
|
-
headers
|
|
37
|
-
});
|
|
38
|
-
const i18n = await initI18n({
|
|
39
|
-
config: payload.config.i18n,
|
|
40
|
-
context: 'client',
|
|
41
|
-
language
|
|
42
|
-
});
|
|
43
|
-
const req = await createLocalReq({
|
|
44
|
-
fallbackLocale: null,
|
|
45
|
-
locale: locale.code,
|
|
46
|
-
req: {
|
|
47
|
-
i18n,
|
|
48
|
-
query: qs.parse(queryString, {
|
|
49
|
-
depth: 10,
|
|
50
|
-
ignoreQueryPrefix: true
|
|
51
|
-
}),
|
|
52
|
-
url: `${payload.config.serverURL}${route}${searchParams ? queryString : ''}`
|
|
53
|
-
}
|
|
54
|
-
}, payload);
|
|
55
|
-
const { permissions, user } = await payload.auth({
|
|
56
|
-
headers,
|
|
57
|
-
req
|
|
58
|
-
});
|
|
59
|
-
req.user = user;
|
|
60
|
-
const visibleEntities = {
|
|
61
|
-
collections: payload.config.collections.map(({ slug, admin: { hidden } })=>!isEntityHidden({
|
|
62
|
-
hidden,
|
|
63
|
-
user
|
|
64
|
-
}) ? slug : null).filter(Boolean),
|
|
65
|
-
globals: payload.config.globals.map(({ slug, admin: { hidden } })=>!isEntityHidden({
|
|
66
|
-
hidden,
|
|
67
|
-
user
|
|
68
|
-
}) ? slug : null).filter(Boolean)
|
|
69
|
-
};
|
|
70
|
-
const { routes: { admin: adminRoute } } = payload.config;
|
|
71
|
-
const routeSegments = route.replace(adminRoute, '').split('/').filter(Boolean);
|
|
72
|
-
const [entityType, entitySlug, createOrID] = routeSegments;
|
|
73
|
-
const collectionSlug = entityType === 'collections' ? entitySlug : undefined;
|
|
74
|
-
const globalSlug = entityType === 'globals' ? entitySlug : undefined;
|
|
75
|
-
const docID = collectionSlug && createOrID !== 'create' ? createOrID : undefined;
|
|
76
|
-
const isAdminRoute = route.startsWith(adminRoute);
|
|
77
|
-
const isAuthRoute = authRoutes.some((r)=>r === route.replace(adminRoute, ''));
|
|
78
|
-
if (redirectUnauthenticatedUser && !user && !isAuthRoute) {
|
|
79
|
-
if (searchParams && 'redirect' in searchParams) delete searchParams.redirect;
|
|
80
|
-
const stringifiedSearchParams = Object.keys(searchParams ?? {}).length ? `?${qs.stringify(searchParams)}` : '';
|
|
81
|
-
redirect(`${routes.admin}/login?redirect=${route + stringifiedSearchParams}`);
|
|
82
|
-
}
|
|
83
|
-
if (!permissions.canAccessAdmin && isAdminRoute && !isAuthRoute) {
|
|
84
|
-
notFound();
|
|
85
|
-
}
|
|
86
|
-
let collectionConfig;
|
|
87
|
-
let globalConfig;
|
|
88
|
-
if (collectionSlug) {
|
|
89
|
-
collectionConfig = collections.find((collection)=>collection.slug === collectionSlug);
|
|
90
|
-
if (!collectionConfig) {
|
|
91
|
-
notFound();
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
if (globalSlug) {
|
|
95
|
-
globalConfig = globals.find((global)=>global.slug === globalSlug);
|
|
96
|
-
if (!globalConfig) {
|
|
97
|
-
notFound();
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return {
|
|
101
|
-
collectionConfig,
|
|
102
|
-
cookies,
|
|
103
|
-
docID,
|
|
104
|
-
globalConfig,
|
|
105
|
-
locale,
|
|
106
|
-
permissions,
|
|
107
|
-
req,
|
|
108
|
-
translations: i18n.translations,
|
|
109
|
-
visibleEntities
|
|
110
|
-
};
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
//# sourceMappingURL=initPage.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/initPage.ts"],"sourcesContent":["import type {\n InitPageResult,\n PayloadRequestWithData,\n SanitizedCollectionConfig,\n SanitizedConfig,\n SanitizedGlobalConfig,\n VisibleEntities,\n} 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 { notFound, redirect } from 'next/navigation.js'\nimport { parseCookies } from 'payload/auth'\nimport { createLocalReq, isEntityHidden } from 'payload/utilities'\nimport qs from 'qs'\n\nimport { getPayloadHMR } from '../utilities/getPayloadHMR.js'\nimport { getRequestLanguage } from './getRequestLanguage.js'\n\ntype Args = {\n config: Promise<SanitizedConfig> | SanitizedConfig\n redirectUnauthenticatedUser?: boolean\n route: string\n searchParams: { [key: string]: string | string[] | undefined }\n}\n\nconst authRoutes = [\n '/login',\n '/logout',\n '/create-first-user',\n '/forgot',\n '/reset',\n '/verify',\n '/logout-inactivity',\n]\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 const { collections, globals, localization, routes } = 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: payload.config.i18n,\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: payload.config.collections\n .map(({ slug, admin: { hidden } }) => (!isEntityHidden({ hidden, user }) ? slug : null))\n .filter(Boolean),\n globals: payload.config.globals\n .map(({ slug, admin: { hidden } }) => (!isEntityHidden({ hidden, user }) ? slug : null))\n .filter(Boolean),\n }\n\n const {\n routes: { admin: adminRoute },\n } = payload.config\n\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 const isAdminRoute = route.startsWith(adminRoute)\n const isAuthRoute = authRoutes.some((r) => r === route.replace(adminRoute, ''))\n\n if (redirectUnauthenticatedUser && !user && !isAuthRoute) {\n if (searchParams && 'redirect' in searchParams) delete searchParams.redirect\n\n const stringifiedSearchParams = Object.keys(searchParams ?? {}).length\n ? `?${qs.stringify(searchParams)}`\n : ''\n\n redirect(`${routes.admin}/login?redirect=${route + stringifiedSearchParams}`)\n }\n\n if (!permissions.canAccessAdmin && isAdminRoute && !isAuthRoute) {\n notFound()\n }\n\n let collectionConfig: SanitizedCollectionConfig\n let globalConfig: SanitizedGlobalConfig\n\n if (collectionSlug) {\n collectionConfig = collections.find((collection) => collection.slug === collectionSlug)\n\n if (!collectionConfig) {\n notFound()\n }\n }\n\n if (globalSlug) {\n globalConfig = globals.find((global) => global.slug === globalSlug)\n\n if (!globalConfig) {\n notFound()\n }\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","notFound","redirect","parseCookies","createLocalReq","isEntityHidden","qs","getPayloadHMR","getRequestLanguage","authRoutes","initPage","config","configPromise","redirectUnauthenticatedUser","route","searchParams","localeParam","locale","payload","collections","globals","localization","routes","queryString","stringify","addQueryPrefix","defaultLocale","localeCode","cookies","language","i18n","context","req","fallbackLocale","code","query","parse","depth","ignoreQueryPrefix","url","serverURL","permissions","user","auth","visibleEntities","map","slug","admin","hidden","filter","Boolean","adminRoute","routeSegments","replace","split","entityType","entitySlug","createOrID","collectionSlug","undefined","globalSlug","docID","isAdminRoute","startsWith","isAuthRoute","some","r","stringifiedSearchParams","Object","keys","length","canAccessAdmin","collectionConfig","globalConfig","find","collection","global","translations"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AASA,SAASA,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,kBAAkB,QAAQ,8CAA6C;AAChF,SAASC,WAAWC,UAAU,QAAQ,kBAAiB;AACvD,SAASC,QAAQ,EAAEC,QAAQ,QAAQ,qBAAoB;AACvD,SAASC,YAAY,QAAQ,eAAc;AAC3C,SAASC,cAAc,EAAEC,cAAc,QAAQ,oBAAmB;AAClE,OAAOC,QAAQ,KAAI;AAEnB,SAASC,aAAa,QAAQ,gCAA+B;AAC7D,SAASC,kBAAkB,QAAQ,0BAAyB;AAS5D,MAAMC,aAAa;IACjB;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED,OAAO,MAAMC,WAAW,OAAO,EAC7BC,QAAQC,aAAa,EACrBC,8BAA8B,KAAK,EACnCC,KAAK,EACLC,YAAY,EACP;IACL,MAAMhB,UAAUC;IAChB,MAAMgB,cAAcD,cAAcE;IAClC,M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