payload-zitadel-plugin 0.1.4 → 0.1.5
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/README.md +1 -1
- package/dist/components/Avatar/index.d.ts +4 -1
- package/dist/components/Avatar/index.d.ts.map +1 -1
- package/dist/components/Avatar/index.js +32 -20
- package/dist/components/Avatar/index.js.map +1 -1
- package/dist/components/LoginButton/button.d.ts +4 -1
- package/dist/components/LoginButton/button.d.ts.map +1 -1
- package/dist/components/LoginButton/button.js +5 -7
- package/dist/components/LoginButton/button.js.map +1 -1
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +1 -1
- package/dist/components/index.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/README.md
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Avatar/index.tsx"],"names":[],"mappings":""}
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Avatar/index.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAC,eAAe,EAAC,MAAM,SAAS,CAAA;AAGvC,eAAO,MAAM,MAAM,EAAE,eAAe,CAAC;IAAE,MAAM,EAAE,OAAO,CAAA;CAAE,CAgCvD,CAAA"}
|
@@ -1,22 +1,34 @@
|
|
1
|
-
|
1
|
+
'use client';
|
2
|
+
import * as React from 'react';
|
3
|
+
// https://github.com/vercel/next.js/issues/46078
|
4
|
+
// import Image from 'next/image.js'
|
5
|
+
import { useSession } from 'next-auth/react';
|
6
|
+
import { DefaultAccountIcon } from '@payloadcms/ui/graphics/Account/Default';
|
7
|
+
export const Avatar = ({ active })=>{
|
8
|
+
const session = useSession();
|
9
|
+
const imageUrl = session?.data?.user?.image;
|
10
|
+
return imageUrl ? /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement("style", null, `
|
11
|
+
.avatar {
|
12
|
+
height: 2rem;
|
13
|
+
width: 2rem;
|
14
|
+
}
|
15
|
+
|
16
|
+
.avatar:hover {
|
17
|
+
filter: brightness(.8);
|
18
|
+
}
|
19
|
+
|
20
|
+
.avatar img {
|
21
|
+
object-fit: fill;
|
22
|
+
border-radius: 100%;
|
23
|
+
}
|
24
|
+
`), /*#__PURE__*/ React.createElement("div", {
|
25
|
+
className: "avatar"
|
26
|
+
}, /*#__PURE__*/ React.createElement("img", {
|
27
|
+
src: imageUrl,
|
28
|
+
alt: "Profile Picture"
|
29
|
+
}))) : /*#__PURE__*/ React.createElement(DefaultAccountIcon, {
|
30
|
+
active: active
|
31
|
+
});
|
32
|
+
};
|
2
33
|
|
3
|
-
import * as React from 'react'
|
4
|
-
import {useSession} from 'next-auth/react'
|
5
|
-
import {CustomComponent} from 'payload'
|
6
|
-
import {Thumbnail} from '@payloadcms/ui/elements/Thumbnail'
|
7
|
-
import {DefaultAccountIcon} from '@payloadcms/ui/graphics/Account/Default'
|
8
|
-
|
9
|
-
|
10
|
-
export const Avatar: CustomComponent = () => {
|
11
|
-
|
12
|
-
const session = useSession()
|
13
|
-
|
14
|
-
const imageUrl = session?.data?.user?.image
|
15
|
-
|
16
|
-
return imageUrl ? (
|
17
|
-
<div className="avatar">
|
18
|
-
<Thumbnail fileSrc={imageUrl} size="expand"/>
|
19
|
-
</div>
|
20
|
-
) : <DefaultAccountIcon active={false}/>
|
21
|
-
}*/
|
22
34
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/components/Avatar/index.tsx"],"sourcesContent":["
|
1
|
+
{"version":3,"sources":["../../../src/components/Avatar/index.tsx"],"sourcesContent":["'use client'\n\nimport * as React from 'react'\n// https://github.com/vercel/next.js/issues/46078\n// import Image from 'next/image.js'\nimport {useSession} from 'next-auth/react'\nimport {DefaultAccountIcon} from '@payloadcms/ui/graphics/Account/Default'\nimport {CustomComponent} from 'payload'\n\n\nexport const Avatar: CustomComponent<{ active: boolean }> = ({active}) => {\n\n const session = useSession()\n\n const imageUrl = session?.data?.user?.image\n\n return (imageUrl ?\n <>\n <style>\n {`\n .avatar {\n height: 2rem;\n width: 2rem;\n }\n \n .avatar:hover {\n filter: brightness(.8);\n }\n \n .avatar img {\n object-fit: fill;\n border-radius: 100%;\n }\n `}\n </style>\n <div className=\"avatar\">\n {/*<Image src={imageUrl} alt=\"Profile Picture\" fill/>*/}\n {<img src={imageUrl} alt=\"Profile Picture\"/>}\n </div>\n </> :\n <DefaultAccountIcon active={active}/>\n )\n}"],"names":["React","useSession","DefaultAccountIcon","Avatar","active","session","imageUrl","data","user","image","style","div","className","img","src","alt"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;AAEA,YAAYA,WAAW,QAAO;AAC9B,iDAAiD;AACjD,oCAAoC;AACpC,SAAQC,UAAU,QAAO,kBAAiB;AAC1C,SAAQC,kBAAkB,QAAO,0CAAyC;AAI1E,OAAO,MAAMC,SAA+C,CAAC,EAACC,MAAM,EAAC;IAEjE,MAAMC,UAAUJ;IAEhB,MAAMK,WAAWD,SAASE,MAAMC,MAAMC;IAEtC,OAAQH,yBACA,wDACI,oBAACI,eACI,CAAC;;;;;;;;;;;;;;wBAcE,CAAC,iBAET,oBAACC;QAAIC,WAAU;qBAEV,oBAACC;QAAIC,KAAKR;QAAUS,KAAI;yBAGjC,oBAACb;QAAmBE,QAAQA;;AAExC,EAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"button.d.ts","sourceRoot":"","sources":["../../../src/components/LoginButton/button.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAC,eAAe,EAAC,MAAM,SAAS,CAAA;
|
1
|
+
{"version":3,"file":"button.d.ts","sourceRoot":"","sources":["../../../src/components/LoginButton/button.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAC,eAAe,EAAC,MAAM,SAAS,CAAA;AAKvC,eAAO,MAAM,YAAY,EAAE,eAAe,CAAC;IACvC,oBAAoB,EAAE,MAAM,CAAC;IAC7B,oBAAoB,EAAE,MAAM,CAAA;CAC/B,CAUA,CAAA"}
|
@@ -1,13 +1,9 @@
|
|
1
1
|
'use client';
|
2
2
|
import React from 'react';
|
3
3
|
import { signIn } from 'next-auth/react';
|
4
|
-
|
5
|
-
import { Button } from '@payloadcms/ui/client';
|
6
|
-
//import {useTranslation} from '@payloadcms/ui/providers/Translation'
|
7
|
-
//import {translations} from '../../translations.js'
|
4
|
+
import { Button, useTranslation } from '@payloadcms/ui';
|
8
5
|
export const _LoginButton = ({ internalProviderName, externalProviderName })=>{
|
9
|
-
|
10
|
-
//const {t} = useTranslation<typeof translations.en, NestedKeysStripped<typeof translations.en>>()
|
6
|
+
const { t } = useTranslation();
|
11
7
|
return /*#__PURE__*/ React.createElement("div", {
|
12
8
|
style: {
|
13
9
|
display: 'flex',
|
@@ -15,7 +11,9 @@ export const _LoginButton = ({ internalProviderName, externalProviderName })=>{
|
|
15
11
|
}
|
16
12
|
}, /*#__PURE__*/ React.createElement(Button, {
|
17
13
|
onClick: ()=>signIn(internalProviderName)
|
18
|
-
},
|
14
|
+
}, t('zitadelPlugin:signIn', {
|
15
|
+
externalProviderName
|
16
|
+
})));
|
19
17
|
};
|
20
18
|
|
21
19
|
//# sourceMappingURL=button.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/components/LoginButton/button.tsx"],"sourcesContent":["'use client'\n\nimport React from 'react'\nimport {signIn} from 'next-auth/react'\nimport {CustomComponent} from 'payload'\
|
1
|
+
{"version":3,"sources":["../../../src/components/LoginButton/button.tsx"],"sourcesContent":["'use client'\n\nimport React from 'react'\nimport {signIn} from 'next-auth/react'\nimport {CustomComponent} from 'payload'\nimport {NestedKeysStripped} from '@payloadcms/translations'\nimport {Button, useTranslation} from '@payloadcms/ui'\nimport {translations} from '../../translations.js'\n\nexport const _LoginButton: CustomComponent<{\n internalProviderName: string,\n externalProviderName: string\n}> = ({internalProviderName, externalProviderName}) => {\n const {t} = useTranslation<typeof translations.en, NestedKeysStripped<typeof translations.en>>()\n\n return (\n <div style={{display: 'flex', justifyContent: 'center'}}>\n <Button onClick={() => signIn(internalProviderName)}>\n {t('zitadelPlugin:signIn', {externalProviderName})}\n </Button>\n </div>\n )\n}"],"names":["React","signIn","Button","useTranslation","_LoginButton","internalProviderName","externalProviderName","t","div","style","display","justifyContent","onClick"],"rangeMappings":";;;;;;;;;;;;;;;;","mappings":"AAAA;AAEA,OAAOA,WAAW,QAAO;AACzB,SAAQC,MAAM,QAAO,kBAAiB;AAGtC,SAAQC,MAAM,EAAEC,cAAc,QAAO,iBAAgB;AAGrD,OAAO,MAAMC,eAGR,CAAC,EAACC,oBAAoB,EAAEC,oBAAoB,EAAC;IAC9C,MAAM,EAACC,CAAC,EAAC,GAAGJ;IAEZ,qBACI,oBAACK;QAAIC,OAAO;YAACC,SAAS;YAAQC,gBAAgB;QAAQ;qBAClD,oBAACT;QAAOU,SAAS,IAAMX,OAAOI;OACzBE,EAAE,wBAAwB;QAACD;IAAoB;AAIhE,EAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,mBAAmB,CAAA;AACxC,OAAO,EAAC,WAAW,EAAC,MAAM,wBAAwB,CAAA;AAClD,OAAO,EAAC,OAAO,EAAC,MAAM,oBAAoB,CAAA"}
|
package/dist/components/index.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/components/index.ts"],"sourcesContent":["
|
1
|
+
{"version":3,"sources":["../../src/components/index.ts"],"sourcesContent":["export {Avatar} from './Avatar/index.js'\nexport {LoginButton} from './LoginButton/index.js'\nexport {Session} from './Session/index.js'"],"names":["Avatar","LoginButton","Session"],"rangeMappings":";;","mappings":"AAAA,SAAQA,MAAM,QAAO,oBAAmB;AACxC,SAAQC,WAAW,QAAO,yBAAwB;AAClD,SAAQC,OAAO,QAAO,qBAAoB"}
|
package/dist/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAA0B,yBAAyB,EAAC,MAAM,YAAY,CAAA;AAI7E,eAAO,MAAM,qBAAqB,EAAE,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAA0B,yBAAyB,EAAC,MAAM,YAAY,CAAA;AAI7E,eAAO,MAAM,qBAAqB,EAAE,yBAoKnC,CAAA"}
|
package/dist/index.js
CHANGED
@@ -3,9 +3,8 @@ import { signOut } from 'next-auth/react';
|
|
3
3
|
import { authOptions } from './options.js';
|
4
4
|
import { zitadelStrategy } from './strategy.js';
|
5
5
|
import { translations } from './translations.js';
|
6
|
-
import { LoginButton, Session } from './components/index.js';
|
7
|
-
export const ZitadelPluginProvider = ({ authSlug = 'users', associatedIdFieldName = 'idp_id',
|
8
|
-
disableLocalStrategy, disableDefaultLoginButton, internalProviderName = 'zitadel', externalProviderName = 'ZITADEL', issuerUrl, clientId, enableAPI, apiClientId, apiKeyId, apiKey })=>{
|
6
|
+
import { Avatar, LoginButton, Session } from './components/index.js';
|
7
|
+
export const ZitadelPluginProvider = ({ authSlug = 'users', associatedIdFieldName = 'idp_id', disableAvatar, disableLocalStrategy, disableDefaultLoginButton, internalProviderName = 'zitadel', externalProviderName = 'ZITADEL', issuerUrl, clientId, enableAPI, apiClientId, apiKeyId, apiKey })=>{
|
9
8
|
if ((issuerUrl ?? '').length == 0) throw new Error('ZITADEL-PLUGIN: ISSUER-URL IS EMPTY');
|
10
9
|
if ((clientId ?? '').length == 0) throw new Error('ZITADEL-PLUGIN: CLIENT-ID IS EMPTY');
|
11
10
|
if (enableAPI) {
|
@@ -23,8 +22,9 @@ disableLocalStrategy, disableDefaultLoginButton, internalProviderName = 'zitadel
|
|
23
22
|
...incomingConfig,
|
24
23
|
admin: {
|
25
24
|
...incomingConfig.admin,
|
26
|
-
|
27
|
-
|
25
|
+
...disableAvatar ? {} : {
|
26
|
+
avatar: Avatar
|
27
|
+
},
|
28
28
|
components: {
|
29
29
|
...incomingConfig.admin?.components,
|
30
30
|
afterLogin: [
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import NextAuth, {getServerSession} from 'next-auth'\nimport {signOut} from 'next-auth/react'\nimport {authOptions} from './options.js'\nimport {zitadelStrategy} from './strategy.js'\nimport {ZitadelAuthOptionsProps, ZitadelPluginProviderType} from './types.js'\nimport {translations} from './translations.js'\nimport {LoginButton, Session} from './components/index.js'\n\nexport const ZitadelPluginProvider: ZitadelPluginProviderType = ({\n authSlug = 'users',\n associatedIdFieldName = 'idp_id',\n //disableAvatar,\n disableLocalStrategy,\n disableDefaultLoginButton,\n internalProviderName = 'zitadel',\n externalProviderName = 'ZITADEL',\n issuerUrl,\n clientId,\n enableAPI,\n apiClientId,\n apiKeyId,\n apiKey\n }) => {\n if ((issuerUrl ?? '').length == 0)\n throw new Error('ZITADEL-PLUGIN: ISSUER-URL IS EMPTY')\n if ((clientId ?? '').length == 0)\n throw new Error('ZITADEL-PLUGIN: CLIENT-ID IS EMPTY')\n if (enableAPI) {\n if ((apiClientId ?? '').length == 0)\n throw new Error('ZITADEL-PLUGIN: API ENABLED, BUT API-CLIENT-ID IS EMPTY')\n if ((apiKeyId ?? '').length == 0)\n throw new Error('ZITADEL-PLUGIN: API ENABLED, BUT API-KEY-ID IS EMPTY')\n if ((apiKey ?? '').length == 0)\n throw new Error('ZITADEL-PLUGIN: API ENABLED, BUT API-KEY IS EMPTY')\n }\n const authOptionsProps: ZitadelAuthOptionsProps = {\n internalProviderName: internalProviderName,\n issuerUrl: issuerUrl!,\n clientId: clientId!\n }\n return {\n zitadelPlugin: (incomingConfig) => ({\n ...incomingConfig,\n admin: {\n ...incomingConfig.admin,\n // currently not working\n //...(disableAvatar ? {} : {avatar: Avatar}),\n components: {\n ...incomingConfig.admin?.components,\n afterLogin: [\n ...incomingConfig.admin?.components?.afterLogin || [],\n ...(disableDefaultLoginButton ? [] : [LoginButton({\n internalProviderName,\n externalProviderName\n })])\n ],\n providers: [\n Session\n ]\n }\n },\n collections: (incomingConfig.collections || []).map((collection) => ({\n ...collection,\n ...collection.slug == authSlug ? {\n auth: {\n ...(typeof collection.auth == 'boolean' ? {} : collection.auth),\n disableLocalStrategy: disableLocalStrategy ? disableLocalStrategy : (typeof collection.auth == 'boolean' ? {} : collection.auth)?.disableLocalStrategy,\n strategies: [\n ...(typeof collection.auth == 'boolean' ? {} : collection.auth)?.strategies ?? [],\n zitadelStrategy({\n authSlug,\n associatedIdFieldName,\n ...authOptionsProps,\n ...(enableAPI ? {\n enableAPI: true,\n apiClientId: apiClientId!,\n apiKeyId: apiClientId!,\n apiKey: apiKey!\n } : {enableAPI: undefined})\n })\n ]\n },\n fields: [\n ...collection.fields,\n {\n name: associatedIdFieldName,\n type: 'text',\n unique: true,\n required: true\n },\n {\n name: 'email',\n type: 'email',\n admin: {\n readOnly: true\n },\n access: {},\n hooks: {\n afterRead: [\n async () => (await getServerSession())?.user?.email\n ]\n }\n },\n {\n name: 'name',\n type: 'text',\n admin: {\n readOnly: true\n },\n access: {},\n hooks: {\n afterRead: [\n async () => (await getServerSession())?.user?.name\n ]\n }\n }\n ],\n hooks: {\n afterLogout: [\n () => signOut()\n ]\n }\n } : {}\n })),\n //would be a more developer-friendly alternative\n //currently not working, maybe in future update\n /*endpoints: [\n ...incomingConfig.endpoints || [],\n ...['get', 'post'].map(method => ({\n handler: NextAuth.default(authOptions(authOptionsProps)),\n method: method as 'get' | 'post',\n path: 'api/auth/*'\n }))\n ],*/\n\n //current work around on creating a non-functional first user\n async onInit(payload) {\n if (incomingConfig.onInit)\n await incomingConfig.onInit(payload)\n\n const existingUsers = await payload.find({\n collection: authSlug,\n limit: 1\n })\n\n if (existingUsers.docs.length === 0) {\n await payload.create({\n collection: authSlug,\n data: {\n email: 'delete.me@now.com',\n password: 'password',\n [associatedIdFieldName]: 'DELETE_ME'\n }\n })\n }\n },\n i18n: {\n ...incomingConfig.i18n,\n translations: {\n ...incomingConfig.i18n?.translations,\n de: {\n ...incomingConfig.i18n?.translations?.de,\n ...translations.de\n },\n en: {\n ...incomingConfig.i18n?.translations?.en,\n ...translations.en\n }\n }\n }\n }),\n nextauthHandler: NextAuth.default(authOptions(authOptionsProps))\n }\n}"],"names":["NextAuth","getServerSession","signOut","authOptions","zitadelStrategy","translations","LoginButton","Session","ZitadelPluginProvider","authSlug","associatedIdFieldName","disableLocalStrategy","disableDefaultLoginButton","internalProviderName","externalProviderName","issuerUrl","clientId","enableAPI","apiClientId","apiKeyId","apiKey","length","Error","authOptionsProps","zitadelPlugin","incomingConfig","admin","components","afterLogin","providers","collections","map","collection","slug","auth","strategies","undefined","fields","name","type","unique","required","readOnly","access","hooks","afterRead","user","email","afterLogout","onInit","payload","existingUsers","find","limit","docs","create","data","password","i18n","de","en","nextauthHandler","default"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,YAAWC,gBAAgB,QAAO,YAAW;AACpD,SAAQC,OAAO,QAAO,kBAAiB;AACvC,SAAQC,WAAW,QAAO,eAAc;AACxC,SAAQC,eAAe,QAAO,gBAAe;AAE7C,SAAQC,YAAY,QAAO,oBAAmB;AAC9C,SAAQC,WAAW,EAAEC,OAAO,QAAO,w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M+C,QAAOC,OAAO;oBAChB,IAAIzB,eAAewB,MAAM,EACrB,MAAMxB,eAAewB,MAAM,CAACC;oBAEhC,MAAMC,gBAAgB,MAAMD,QAAQE,IAAI,CAAC;wBACrCpB,YAAYvB;wBACZ4C,OAAO;oBACX;oBAEA,IAAIF,cAAcG,IAAI,CAACjC,MAAM,KAAK,GAAG;wBACjC,MAAM6B,QAAQK,MAAM,CAAC;4BACjBvB,YAAYvB;4BACZ+C,MAAM;gCACFT,OAAO;gCACPU,UAAU;gCACV,CAAC/C,sBAAsB,EAAE;4BAC7B;wBACJ;oBACJ;gBACJ;gBACAgD,MAAM;oBACF,GAAGjC,eAAeiC,IAAI;oBACtBrD,cAAc;wBACV,GAAGoB,eAAeiC,IAAI,EAAErD,YAAY;wBACpCsD,IAAI;4BACA,GAAGlC,eAAeiC,IAAI,EAAErD,cAAcsD,EAAE;4BACxC,GAAGtD,aAAasD,EAAE;wBACtB;wBACAC,IAAI;4BACA,GAAGnC,eAAeiC,IAAI,EAAErD,cAAcuD,EAAE;4BACxC,GAAGvD,aAAauD,EAAE;wBACtB;oBACJ;gBACJ;YACJ,CAAA;QACAC,iBAAiB7D,SAAS8D,OAAO,CAAC3D,YAAYoB;IAClD;AACJ,EAAC"}
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import NextAuth, {getServerSession} from 'next-auth'\nimport {signOut} from 'next-auth/react'\nimport {authOptions} from './options.js'\nimport {zitadelStrategy} from './strategy.js'\nimport {ZitadelAuthOptionsProps, ZitadelPluginProviderType} from './types.js'\nimport {translations} from './translations.js'\nimport {Avatar, LoginButton, Session} from './components/index.js'\n\nexport const ZitadelPluginProvider: ZitadelPluginProviderType = ({\n authSlug = 'users',\n associatedIdFieldName = 'idp_id',\n disableAvatar,\n disableLocalStrategy,\n disableDefaultLoginButton,\n internalProviderName = 'zitadel',\n externalProviderName = 'ZITADEL',\n issuerUrl,\n clientId,\n enableAPI,\n apiClientId,\n apiKeyId,\n apiKey\n }) => {\n if ((issuerUrl ?? '').length == 0)\n throw new Error('ZITADEL-PLUGIN: ISSUER-URL IS EMPTY')\n if ((clientId ?? '').length == 0)\n throw new Error('ZITADEL-PLUGIN: CLIENT-ID IS EMPTY')\n if (enableAPI) {\n if ((apiClientId ?? '').length == 0)\n throw new Error('ZITADEL-PLUGIN: API ENABLED, BUT API-CLIENT-ID IS EMPTY')\n if ((apiKeyId ?? '').length == 0)\n throw new Error('ZITADEL-PLUGIN: API ENABLED, BUT API-KEY-ID IS EMPTY')\n if ((apiKey ?? '').length == 0)\n throw new Error('ZITADEL-PLUGIN: API ENABLED, BUT API-KEY IS EMPTY')\n }\n const authOptionsProps: ZitadelAuthOptionsProps = {\n internalProviderName: internalProviderName,\n issuerUrl: issuerUrl!,\n clientId: clientId!\n }\n return {\n zitadelPlugin: (incomingConfig) => ({\n ...incomingConfig,\n admin: {\n ...incomingConfig.admin,\n ...(disableAvatar ? {} : {avatar: Avatar}),\n components: {\n ...incomingConfig.admin?.components,\n afterLogin: [\n ...incomingConfig.admin?.components?.afterLogin || [],\n ...(disableDefaultLoginButton ? [] : [LoginButton({\n internalProviderName,\n externalProviderName\n })])\n ],\n providers: [\n Session\n ]\n }\n },\n collections: (incomingConfig.collections || []).map((collection) => ({\n ...collection,\n ...collection.slug == authSlug ? {\n auth: {\n ...(typeof collection.auth == 'boolean' ? {} : collection.auth),\n disableLocalStrategy: disableLocalStrategy ? disableLocalStrategy : (typeof collection.auth == 'boolean' ? {} : collection.auth)?.disableLocalStrategy,\n strategies: [\n ...(typeof collection.auth == 'boolean' ? {} : collection.auth)?.strategies ?? [],\n zitadelStrategy({\n authSlug,\n associatedIdFieldName,\n ...authOptionsProps,\n ...(enableAPI ? {\n enableAPI: true,\n apiClientId: apiClientId!,\n apiKeyId: apiClientId!,\n apiKey: apiKey!\n } : {enableAPI: undefined})\n })\n ]\n },\n fields: [\n ...collection.fields,\n {\n name: associatedIdFieldName,\n type: 'text',\n unique: true,\n required: true\n },\n {\n name: 'email',\n type: 'email',\n admin: {\n readOnly: true\n },\n access: {},\n hooks: {\n afterRead: [\n async () => (await getServerSession())?.user?.email\n ]\n }\n },\n {\n name: 'name',\n type: 'text',\n admin: {\n readOnly: true\n },\n access: {},\n hooks: {\n afterRead: [\n async () => (await getServerSession())?.user?.name\n ]\n }\n }\n ],\n hooks: {\n afterLogout: [\n () => signOut()\n ]\n }\n } : {}\n })),\n //would be a more developer-friendly alternative\n //currently not working, maybe in future update\n /*endpoints: [\n ...incomingConfig.endpoints || [],\n ...['get', 'post'].map(method => ({\n handler: NextAuth.default(authOptions(authOptionsProps)),\n method: method as 'get' | 'post',\n path: 'api/auth/*'\n }))\n ],*/\n\n //current work around on creating a non-functional first user\n async onInit(payload) {\n if (incomingConfig.onInit)\n await incomingConfig.onInit(payload)\n\n const existingUsers = await payload.find({\n collection: authSlug,\n limit: 1\n })\n\n if (existingUsers.docs.length === 0) {\n await payload.create({\n collection: authSlug,\n data: {\n email: 'delete.me@now.com',\n password: 'password',\n [associatedIdFieldName]: 'DELETE_ME'\n }\n })\n }\n },\n i18n: {\n ...incomingConfig.i18n,\n translations: {\n ...incomingConfig.i18n?.translations,\n de: {\n ...incomingConfig.i18n?.translations?.de,\n ...translations.de\n },\n en: {\n ...incomingConfig.i18n?.translations?.en,\n ...translations.en\n }\n }\n }\n }),\n nextauthHandler: NextAuth.default(authOptions(authOptionsProps))\n }\n}"],"names":["NextAuth","getServerSession","signOut","authOptions","zitadelStrategy","translations","Avatar","LoginButton","Session","ZitadelPluginProvider","authSlug","associatedIdFieldName","disableAvatar","disableLocalStrategy","disableDefaultLoginButton","internalProviderName","externalProviderName","issuerUrl","clientId","enableAPI","apiClientId","apiKeyId","apiKey","length","Error","authOptionsProps","zitadelPlugin","incomingConfig","admin","avatar","components","afterLogin","providers","collections","map","collection","slug","auth","strategies","undefined","fields","name","type","unique","required","readOnly","access","hooks","afterRead","user","email","afterLogout","onInit","payload","existingUsers","find","limit","docs","create","data","password","i18n","de","en","n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ACJ,EAAC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "payload-zitadel-plugin",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.5",
|
4
4
|
"description": "plugin for Payload CMS, which enables authentication via Zitadel IdP",
|
5
5
|
"type": "module",
|
6
6
|
"license": "MIT",
|
@@ -36,24 +36,24 @@
|
|
36
36
|
"dist"
|
37
37
|
],
|
38
38
|
"dependencies": {
|
39
|
-
"@payloadcms/translations": "3.0.0-beta.
|
40
|
-
"@payloadcms/ui": "3.0.0-beta.
|
39
|
+
"@payloadcms/translations": "3.0.0-beta.53",
|
40
|
+
"@payloadcms/ui": "3.0.0-beta.53",
|
41
41
|
"jsonwebtoken": "^9.0.2",
|
42
42
|
"next": "^15.0.0-rc.0",
|
43
43
|
"next-auth": "^4.24.7",
|
44
|
-
"payload": "3.0.0-beta.
|
44
|
+
"payload": "3.0.0-beta.53",
|
45
45
|
"react": "rc",
|
46
46
|
"react-dom": "rc"
|
47
47
|
},
|
48
48
|
"devDependencies": {
|
49
49
|
"@swc/cli": "^0.3.12",
|
50
|
-
"@swc/core": "^1.6.
|
50
|
+
"@swc/core": "^1.6.3",
|
51
51
|
"@types/jsonwebtoken": "^9.0.6",
|
52
|
-
"@types/node": "^20.14.
|
52
|
+
"@types/node": "^20.14.6",
|
53
53
|
"@types/react": "^18.3.3",
|
54
54
|
"@types/react-dom": "^18.3.0",
|
55
55
|
"rimraf": "^5.0.7",
|
56
|
-
"typescript": "^5.
|
56
|
+
"typescript": "^5.5.1-rc"
|
57
57
|
},
|
58
58
|
"engines": {
|
59
59
|
"node": "^22.3.0"
|