payload-zitadel-plugin 0.1.4 → 0.1.6

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 CHANGED
@@ -10,7 +10,7 @@ uses [NextAuth.js](https://next-auth.js.org) under the hood.
10
10
  ## Install
11
11
 
12
12
  ```shell
13
- pnpm add payload-zitadel-plugin@0.1.3
13
+ pnpm add payload-zitadel-plugin@0.1.6
14
14
  ```
15
15
 
16
16
  ## Configuration
@@ -1,2 +1,5 @@
1
- export {};
1
+ import { CustomComponent } from 'payload';
2
+ export declare const Avatar: CustomComponent<{
3
+ active: boolean;
4
+ }>;
2
5
  //# sourceMappingURL=index.d.ts.map
@@ -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
- /*'use client'
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":["/*'use client'\n\nimport * as React from 'react'\nimport {useSession} from 'next-auth/react'\nimport {CustomComponent} from 'payload'\nimport {Thumbnail} from '@payloadcms/ui/elements/Thumbnail'\nimport {DefaultAccountIcon} from '@payloadcms/ui/graphics/Account/Default'\n\n\nexport const Avatar: CustomComponent = () => {\n\n const session = useSession()\n\n const imageUrl = session?.data?.user?.image\n\n return imageUrl ? (\n <div className=\"avatar\">\n <Thumbnail fileSrc={imageUrl} size=\"expand\"/>\n </div>\n ) : <DefaultAccountIcon active={false}/>\n}*/"],"names":[],"rangeMappings":";;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;;;;;;;;;;;;;;;;;;;CAoBC,GApBD"}
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,3 +1,6 @@
1
1
  import { CustomComponent } from 'payload';
2
- export declare const _LoginButton: CustomComponent;
2
+ export declare const _LoginButton: CustomComponent<{
3
+ internalProviderName: string;
4
+ externalProviderName: string;
5
+ }>;
3
6
  //# sourceMappingURL=button.d.ts.map
@@ -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;AAMvC,eAAO,MAAM,YAAY,EAAE,eAe1B,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
- //import {NestedKeysStripped} from '@payloadcms/translations'
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
- //currently not working
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
- }, externalProviderName));
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'\n//import {NestedKeysStripped} from '@payloadcms/translations'\nimport {Button} from '@payloadcms/ui/client'\n//import {useTranslation} from '@payloadcms/ui/providers/Translation'\n//import {translations} from '../../translations.js'\n\nexport const _LoginButton: CustomComponent = ({internalProviderName, externalProviderName}: {\n internalProviderName: string,\n externalProviderName: string\n}) => {\n //currently not working\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 {externalProviderName}\n </Button>\n </div>\n )\n}"],"names":["React","signIn","Button","_LoginButton","internalProviderName","externalProviderName","div","style","display","justifyContent","onClick"],"rangeMappings":";;;;;;;;;;;;;;;;;;","mappings":"AAAA;AAEA,OAAOA,WAAW,QAAO;AACzB,SAAQC,MAAM,QAAO,kBAAiB;AAEtC,6DAA6D;AAC7D,SAAQC,MAAM,QAAO,wBAAuB;AAC5C,qEAAqE;AACrE,oDAAoD;AAEpD,OAAO,MAAMC,eAAgC,CAAC,EAACC,oBAAoB,EAAEC,oBAAoB,EAGxF;IACG,uBAAuB;IACvB,kGAAkG;IAElG,qBACI,oBAACC;QAAIC,OAAO;YAACC,SAAS;YAAQC,gBAAgB;QAAQ;qBAClD,oBAACP;QAAOQ,SAAS,IAAMT,OAAOG;OAEzBC;AAIjB,EAAC"}
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,3 +1,4 @@
1
+ export { Avatar } from './Avatar/index.js';
1
2
  export { LoginButton } from './LoginButton/index.js';
2
3
  export { Session } from './Session/index.js';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,WAAW,EAAC,MAAM,wBAAwB,CAAA;AAClD,OAAO,EAAC,OAAO,EAAC,MAAM,oBAAoB,CAAA"}
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"}
@@ -1,4 +1,4 @@
1
- //export {Avatar} from './Avatar/index.js'
1
+ export { Avatar } from './Avatar/index.js';
2
2
  export { LoginButton } from './LoginButton/index.js';
3
3
  export { Session } from './Session/index.js';
4
4
 
@@ -1 +1 @@
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":["LoginButton","Session"],"rangeMappings":";;","mappings":"AAAA,0CAA0C;AAC1C,SAAQA,WAAW,QAAO,yBAAwB;AAClD,SAAQC,OAAO,QAAO,qBAAoB"}
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"}
@@ -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,yBAqKnC,CAAA"}
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', //disableAvatar,
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
- // currently not working
27
- //...(disableAvatar ? {} : {avatar: Avatar}),
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,Q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L;gCACJ;6BACH;4BACDM,OAAO;gCACHI,aAAa;oCACT,IAAM9C;iCACT;4BACL;wBACJ,IAAI,CAAC,CAAC;oBACV,CAAA;gBACA,gDAAgD;gBAChD,+CAA+C;gBAC/C;;;;;;;cAOE,GAEF,6DAA6D;gBAC7D,MAAM+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","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,MAAM,EAAEC,WAAW,EAAEC,OAAO,QAAO,wBAAuB;AAElE,OAAO,MAAMC,wBAAmD,CAAC,EACIC,WAAW,OAAO,EAClBC,wBAAwB,QAAQ,EAChCC,aAAa,EACbC,oBAAoB,EACpBC,yBAAyB,EACzBC,uBAAuB,SAAS,EAChCC,uBAAuB,SAAS,EAChCC,SAAS,EACTC,QAAQ,EACRC,SAAS,EACTC,WAAW,EACXC,QAAQ,EACRC,MAAM,EACT;IAC9D,IAAI,AAACL,CAAAA,aAAa,EAAC,EAAGM,MAAM,IAAI,GAC5B,MAAM,IAAIC,MAAM;IACpB,IAAI,AAACN,CAAAA,YAAY,EAAC,EAAGK,MAAM,IAAI,GAC3B,MAAM,IAAIC,MAAM;IACpB,IAAIL,WAAW;QACX,IAAI,AAACC,CAAAA,eAAe,EAAC,EAAGG,MAAM,IAAI,GAC9B,MAAM,IAAIC,MAAM;QACpB,IAAI,AAACH,CAAAA,YAAY,EAAC,EAAGE,MAAM,IAAI,GAC3B,MAAM,IAAIC,MAAM;QACpB,IAAI,A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BACAC,IAAI;4BACA,GAAGpC,eAAekC,IAAI,EAAExD,cAAc0D,EAAE;4BACxC,GAAG1D,aAAa0D,EAAE;wBACtB;oBACJ;gBACJ;YACJ,CAAA;QACAC,iBAAiBhE,SAASiE,OAAO,CAAC9D,YAAYsB;IAClD;AACJ,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,sBAAsB,EAAC,MAAM,YAAY,CAAA;AAEjD,eAAO,MAAM,WAAW,EAAE,sBA4CxB,CAAA"}
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,sBAAsB,EAAC,MAAM,YAAY,CAAA;AAEjD,eAAO,MAAM,WAAW,EAAE,sBA8CxB,CAAA"}
package/dist/options.js CHANGED
@@ -22,25 +22,29 @@ export const authOptions = ({ internalProviderName, issuerUrl, clientId })=>({
22
22
  profile: async (profile)=>({
23
23
  id: profile.sub,
24
24
  name: profile.name,
25
- firstName: profile.given_name,
26
- lastName: profile.family_name,
27
25
  email: profile.email,
28
26
  loginName: profile.preferred_username,
29
- image: profile.picture
27
+ image: profile.picture,
28
+ firstName: profile.given_name,
29
+ lastName: profile.family_name,
30
+ gender: profile.gender,
31
+ locale: profile.locale,
32
+ roles: profile['urn:zitadel:iam:org:project:roles']
30
33
  }),
31
- userinfo: {
32
- async request (context) {
33
- return await context.client.userinfo(context.tokens.access_token);
34
- }
35
- },
36
34
  clientId
37
35
  }
38
36
  ],
39
37
  callbacks: {
38
+ jwt: async ({ user, token })=>({
39
+ ...token,
40
+ ...user ? {
41
+ user
42
+ } : {}
43
+ }),
40
44
  session: async ({ session, token })=>({
41
45
  ...session,
42
46
  user: {
43
- id: token.sub,
47
+ ...token.user,
44
48
  ...session.user
45
49
  }
46
50
  })
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/options.ts"],"sourcesContent":["import {ZitadelAuthOptionsType} from './types.js'\n\nexport const authOptions: ZitadelAuthOptionsType = ({internalProviderName, issuerUrl, clientId}) => ({\n providers: [\n {\n id: internalProviderName,\n name: internalProviderName,\n type: 'oauth',\n version: '2',\n wellKnown: issuerUrl,\n authorization: {\n params: {\n scope: 'openid email profile'\n }\n },\n idToken: true,\n checks: ['pkce', 'state'],\n client: {\n token_endpoint_auth_method: 'none'\n },\n profile: async (profile) => ({\n id: profile.sub,\n name: profile.name,\n firstName: profile.given_name,\n lastName: profile.family_name,\n email: profile.email,\n loginName: profile.preferred_username,\n image: profile.picture\n }),\n userinfo: {\n async request(context) {\n return await context.client.userinfo(context.tokens.access_token!)\n }\n },\n clientId\n }\n ],\n callbacks: {\n session: async ({session, token}) => ({\n ...session,\n user: {\n id: token.sub,\n ...session.user\n }\n })\n }\n})"],"names":["authOptions","internalProviderName","issuerUrl","clientId","providers","id","name","type","version","wellKnown","authorization","params","scope","idToken","checks","client","token_endpoint_auth_method","profile","sub","firstName","given_name","lastName","family_name","email","loginName","preferred_username","image","picture","userinfo","request","context","tokens","access_token","callbacks","session","token","user"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,OAAO,MAAMA,cAAsC,CAAC,EAACC,oBAAoB,EAAEC,SAAS,EAAEC,QAAQ,EAAC,GAAM,CAAA;QACjGC,WAAW;YACP;gBACIC,IAAIJ;gBACJK,MAAML;gBACNM,MAAM;gBACNC,SAAS;gBACTC,WAAWP;gBACXQ,eAAe;oBACXC,QAAQ;wBACJC,OAAO;oBACX;gBACJ;gBACAC,SAAS;gBACTC,QAAQ;oBAAC;oBAAQ;iBAAQ;gBACzBC,QAAQ;oBACJC,4BAA4B;gBAChC;gBACAC,SAAS,OAAOA,UAAa,CAAA;wBACzBZ,IAAIY,QAAQC,GAAG;wBACfZ,MAAMW,QAAQX,IAAI;wBAClBa,WAAWF,QAAQG,UAAU;wBAC7BC,UAAUJ,QAAQK,WAAW;wBAC7BC,OAAON,QAAQM,KAAK;wBACpBC,WAAWP,QAAQQ,kBAAkB;wBACrCC,OAAOT,QAAQU,OAAO;oBAC1B,CAAA;gBACAC,UAAU;oBACN,MAAMC,SAAQC,OAAO;wBACjB,OAAO,MAAMA,QAAQf,MAAM,CAACa,QAAQ,CAACE,QAAQC,MAAM,CAACC,YAAY;oBACpE;gBACJ;gBACA7B;YACJ;SACH;QACD8B,WAAW;YACPC,SAAS,OAAO,EAACA,OAAO,EAAEC,KAAK,EAAC,GAAM,CAAA;oBAClC,GAAGD,OAAO;oBACVE,MAAM;wBACF/B,IAAI8B,MAAMjB,GAAG;wBACb,GAAGgB,QAAQE,IAAI;oBACnB;gBACJ,CAAA;QACJ;IACJ,CAAA,EAAE"}
1
+ {"version":3,"sources":["../src/options.ts"],"sourcesContent":["import {ZitadelAuthOptionsType} from './types.js'\n\nexport const authOptions: ZitadelAuthOptionsType = ({internalProviderName, issuerUrl, clientId}) => ({\n providers: [\n {\n id: internalProviderName,\n name: internalProviderName,\n type: 'oauth',\n version: '2',\n wellKnown: issuerUrl,\n authorization: {\n params: {\n scope: 'openid email profile'\n }\n },\n idToken: true,\n checks: ['pkce', 'state'],\n client: {\n token_endpoint_auth_method: 'none'\n },\n profile: async (profile) => ({\n id: profile.sub,\n name: profile.name,\n email: profile.email,\n loginName: profile.preferred_username,\n image: profile.picture,\n firstName: profile.given_name,\n lastName: profile.family_name,\n gender: profile.gender,\n locale: profile.locale,\n roles: profile['urn:zitadel:iam:org:project:roles'],\n }),\n clientId\n }\n ],\n callbacks: {\n jwt: async ({user, token}) => ({\n ...token,\n ...(user ? {user} : {})\n }),\n session: async ({session, token}) => ({\n ...session,\n user: {\n ...token.user,\n ...session.user\n }\n })\n }\n})"],"names":["authOptions","internalProviderName","issuerUrl","clientId","providers","id","name","type","version","wellKnown","authorization","params","scope","idToken","checks","client","token_endpoint_auth_method","profile","sub","email","loginName","preferred_username","image","picture","firstName","given_name","lastName","family_name","gender","locale","roles","callbacks","jwt","user","token","session"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,OAAO,MAAMA,cAAsC,CAAC,EAACC,oBAAoB,EAAEC,SAAS,EAAEC,QAAQ,EAAC,GAAM,CAAA;QACjGC,WAAW;YACP;gBACIC,IAAIJ;gBACJK,MAAML;gBACNM,MAAM;gBACNC,SAAS;gBACTC,WAAWP;gBACXQ,eAAe;oBACXC,QAAQ;wBACJC,OAAO;oBACX;gBACJ;gBACAC,SAAS;gBACTC,QAAQ;oBAAC;oBAAQ;iBAAQ;gBACzBC,QAAQ;oBACJC,4BAA4B;gBAChC;gBACAC,SAAS,OAAOA,UAAa,CAAA;wBACzBZ,IAAIY,QAAQC,GAAG;wBACfZ,MAAMW,QAAQX,IAAI;wBAClBa,OAAOF,QAAQE,KAAK;wBACpBC,WAAWH,QAAQI,kBAAkB;wBACrCC,OAAOL,QAAQM,OAAO;wBACtBC,WAAWP,QAAQQ,UAAU;wBAC7BC,UAAUT,QAAQU,WAAW;wBAC7BC,QAAQX,QAAQW,MAAM;wBACtBC,QAAQZ,QAAQY,MAAM;wBACtBC,OAAOb,OAAO,CAAC,oCAAoC;oBACvD,CAAA;gBACAd;YACJ;SACH;QACD4B,WAAW;YACPC,KAAK,OAAO,EAACC,IAAI,EAAEC,KAAK,EAAC,GAAM,CAAA;oBAC3B,GAAGA,KAAK;oBACR,GAAID,OAAO;wBAACA;oBAAI,IAAI,CAAC,CAAC;gBAC1B,CAAA;YACAE,SAAS,OAAO,EAACA,OAAO,EAAED,KAAK,EAAC,GAAM,CAAA;oBAClC,GAAGC,OAAO;oBACVF,MAAM;wBACF,GAAGC,MAAMD,IAAI;wBACb,GAAGE,QAAQF,IAAI;oBACnB;gBACJ,CAAA;QACJ;IACJ,CAAA,EAAE"}
package/dist/types.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { NextAuthOptions } from 'next-auth';
1
+ import { Awaitable, NextAuthOptions, Session } from 'next-auth';
2
2
  import { AuthStrategy } from 'payload';
3
3
  import { Config } from 'payload';
4
+ import { JWT } from 'next-auth/jwt';
4
5
  export type ZitadelPluginProps = {
5
6
  disableAvatar?: true | undefined;
6
7
  disableLocalStrategy?: true | undefined;
@@ -17,7 +18,16 @@ export type ZitadelAuthOptionsProps = {
17
18
  issuerUrl: string;
18
19
  clientId: string;
19
20
  };
20
- export type ZitadelAuthOptionsType = (props: ZitadelAuthOptionsProps) => NextAuthOptions;
21
+ export type ZitadelAuthOptionsType = (props: ZitadelAuthOptionsProps) => NextAuthOptions & {
22
+ callbacks: {
23
+ session: (props: {
24
+ session: Session;
25
+ token: JWT & {
26
+ user: any;
27
+ };
28
+ }) => Awaitable<Session>;
29
+ };
30
+ };
21
31
  export type ZitadelAPIProps = {
22
32
  enableAPI: true;
23
33
  apiClientId: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,WAAW,CAAA;AACzC,OAAO,EAAC,YAAY,EAAC,MAAM,SAAS,CAAA;AACpC,OAAO,EAAC,MAAM,EAAC,MAAM,SAAS,CAAA;AAE9B,MAAM,MAAM,kBAAkB,GAAG;IAC7B,aAAa,CAAC,EAAE,IAAI,GAAG,SAAS,CAAA;IAChC,oBAAoB,CAAC,EAAE,IAAI,GAAG,SAAS,CAAA;IACvC,yBAAyB,CAAC,EAAE,IAAI,GAAG,SAAS,CAAA;IAC5C,uBAAuB,CAAC,EAAE,MAAM,CAAA;IAChC,oBAAoB,CAAC,EAAE,MAAM,CAAA;CAChC,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAA;AAEjC,MAAM,MAAM,yBAAyB,GAAG,CAAC,KAAK,EAAE,kBAAkB,KAAK;IACnE,aAAa,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,MAAM,CAAC;IAClD,eAAe,EAAE,GAAG,CAAA;CACvB,CA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CAChC,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAA;AAEjC,MAAM,MAAM,yBAAyB,GAAG,CAAC,KAAK,EAAE,kBAAkB,KAAK;IACnE,aAAa,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,MAAM,CAAC;IAClD,eAAe,EAAE,GAAG,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,uBAAuB,GAAG;IAClC,oBAAoB,EAAE,MAAM,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,sBAAsB,GAAG,CAAC,KAAK,EAAE,uBAAuB,KAAK,eAAe,GAAG;IACvF,SAAS,EAAE;QAAE,OAAO,EAAE,CAAC,KAAK,EAAE;YAAE,OAAO,EAAE,OAAO,CAAC;YAAC,KAAK,EAAE,GAAG,GAAG;gBAAE,IAAI,EAAE,GAAG,CAAA;aAAE,CAAA;SAAE,KAAK,SAAS,CAAC,OAAO,CAAC,CAAA;KAAE,CAAA;CAC1G,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC1B,SAAS,EAAE,IAAI,CAAA;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG,uBAAuB,GAAG;IACzD,QAAQ,EAAE,MAAM,CAAC;IACjB,qBAAqB,EAAE,MAAM,CAAC;CACjC,GAAG,CAAC,eAAe,GAAG;IACnB,SAAS,CAAC,EAAE,SAAS,CAAA;CACxB,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC,CAAA;AAE7B,MAAM,MAAM,mBAAmB,GAAG,CAAC,KAAK,EAAE,oBAAoB,KAAK,YAAY,CAAA"}
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import {NextAuthOptions} from 'next-auth'\nimport {AuthStrategy} from 'payload'\nimport {Config} from 'payload'\n\nexport type ZitadelPluginProps = {\n disableAvatar?: true | undefined\n disableLocalStrategy?: true | undefined\n disableDefaultLoginButton?: true | undefined\n defaultLoginButtonTitle?: string\n externalProviderName?: string\n} & Partial<ZitadelStrategyProps>\n\nexport type ZitadelPluginProviderType = (props: ZitadelPluginProps) => {\n zitadelPlugin: (incomingConfig: Config) => Config,\n nextauthHandler: any\n}\n\nexport type ZitadelAuthOptionsProps = {\n internalProviderName: string,\n issuerUrl: string,\n clientId: string\n}\n\nexport type ZitadelAuthOptionsType = (props: ZitadelAuthOptionsProps) => NextAuthOptions\n\nexport type ZitadelAPIProps = {\n enableAPI: true\n apiClientId: string,\n apiKeyId: string,\n apiKey: string\n}\n\nexport type ZitadelStrategyProps = ZitadelAuthOptionsProps & {\n authSlug: string,\n associatedIdFieldName: string,\n} & (ZitadelAPIProps | {\n enableAPI?: undefined\n} & Partial<ZitadelAPIProps>)\n\nexport type ZitadelStrategyType = (props: ZitadelStrategyProps) => AuthStrategy"],"names":[],"rangeMappings":"","mappings":"AAuCA,WAA+E"}
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import {Awaitable, NextAuthOptions, Session} from 'next-auth'\nimport {AuthStrategy} from 'payload'\nimport {Config} from 'payload'\nimport {JWT} from 'next-auth/jwt'\n\nexport type ZitadelPluginProps = {\n disableAvatar?: true | undefined\n disableLocalStrategy?: true | undefined\n disableDefaultLoginButton?: true | undefined\n defaultLoginButtonTitle?: string\n externalProviderName?: string\n} & Partial<ZitadelStrategyProps>\n\nexport type ZitadelPluginProviderType = (props: ZitadelPluginProps) => {\n zitadelPlugin: (incomingConfig: Config) => Config,\n nextauthHandler: any\n}\n\nexport type ZitadelAuthOptionsProps = {\n internalProviderName: string,\n issuerUrl: string,\n clientId: string\n}\n\nexport type ZitadelAuthOptionsType = (props: ZitadelAuthOptionsProps) => NextAuthOptions & {\n callbacks: { session: (props: { session: Session, token: JWT & { user: any } }) => Awaitable<Session> }\n}\n\nexport type ZitadelAPIProps = {\n enableAPI: true\n apiClientId: string,\n apiKeyId: string,\n apiKey: string\n}\n\nexport type ZitadelStrategyProps = ZitadelAuthOptionsProps & {\n authSlug: string,\n associatedIdFieldName: string,\n} & (ZitadelAPIProps | {\n enableAPI?: undefined\n} & Partial<ZitadelAPIProps>)\n\nexport type ZitadelStrategyType = (props: ZitadelStrategyProps) => AuthStrategy"],"names":[],"rangeMappings":"","mappings":"AA0CA,WAA+E"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payload-zitadel-plugin",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
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.52",
40
- "@payloadcms/ui": "3.0.0-beta.52",
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.52",
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.1",
50
+ "@swc/core": "^1.6.3",
51
51
  "@types/jsonwebtoken": "^9.0.6",
52
- "@types/node": "^20.14.5",
52
+ "@types/node": "^20.14.7",
53
53
  "@types/react": "^18.3.3",
54
54
  "@types/react-dom": "^18.3.0",
55
55
  "rimraf": "^5.0.7",
56
- "typescript": "^5.6.0-dev.20240618"
56
+ "typescript": "^5.5.2"
57
57
  },
58
58
  "engines": {
59
59
  "node": "^22.3.0"