payload-zitadel-plugin 0.1.1 → 0.1.3
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 +47 -11
- package/dist/components/Avatar/index.d.ts +5 -0
- package/dist/components/Avatar/index.d.ts.map +1 -0
- package/dist/components/Avatar/index.js +20 -0
- package/dist/components/Avatar/index.js.map +1 -0
- package/dist/components/LoginButton/button.d.ts +3 -0
- package/dist/components/LoginButton/button.d.ts.map +1 -0
- package/dist/components/LoginButton/button.js +21 -0
- package/dist/components/LoginButton/button.js.map +1 -0
- package/dist/components/LoginButton/index.d.ts.map +1 -0
- package/dist/components/LoginButton/index.js.map +1 -0
- package/dist/components/Session/index.d.ts +4 -0
- package/dist/components/Session/index.d.ts.map +1 -0
- package/dist/components/Session/index.js +6 -0
- package/dist/components/Session/index.js.map +1 -0
- package/dist/components/index.d.ts +4 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +5 -0
- package/dist/components/index.js.map +1 -0
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +38 -6
- package/dist/index.js.map +1 -1
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +7 -2
- package/dist/options.js.map +1 -1
- package/dist/types.d.ts +3 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +9 -9
- package/dist/LoginButton/button.d.ts +0 -3
- package/dist/LoginButton/button.d.ts.map +0 -1
- package/dist/LoginButton/button.js +0 -20
- package/dist/LoginButton/button.js.map +0 -1
- package/dist/LoginButton/index.d.ts.map +0 -1
- package/dist/LoginButton/index.js.map +0 -1
- /package/dist/{LoginButton → components/LoginButton}/index.d.ts +0 -0
- /package/dist/{LoginButton → components/LoginButton}/index.js +0 -0
package/README.md
CHANGED
@@ -17,10 +17,9 @@ pnpm add payload-zitadel-plugin@0.1.0
|
|
17
17
|
|
18
18
|
Initialize the plugin in Payload Config File. Change the parameters to connect to your Zitadel Instance.
|
19
19
|
|
20
|
-
####
|
20
|
+
#### zitadel-plugin.ts
|
21
21
|
|
22
22
|
```typescript
|
23
|
-
import {buildConfig} from 'payload/config'
|
24
23
|
import {ZitadelPluginProvider} from 'payload-zitadel-plugin'
|
25
24
|
|
26
25
|
export const {zitadelPlugin, nextauthHandler} = ZitadelPluginProvider({
|
@@ -31,6 +30,9 @@ export const {zitadelPlugin, nextauthHandler} = ZitadelPluginProvider({
|
|
31
30
|
// interpolation text for the Login Button - "sign in with ..."
|
32
31
|
// externalProviderName: 'ZITADEL',
|
33
32
|
|
33
|
+
// set to true if you do not want to use the IdP Profile as the Avatar
|
34
|
+
// disableAvatar: true
|
35
|
+
|
34
36
|
// set to true if you want to use your own custom login button
|
35
37
|
// disableDefaultLoginButton: true
|
36
38
|
|
@@ -55,6 +57,13 @@ export const {zitadelPlugin, nextauthHandler} = ZitadelPluginProvider({
|
|
55
57
|
// apiKey: process.env.ZITADEL_API_KEY
|
56
58
|
})
|
57
59
|
|
60
|
+
```
|
61
|
+
|
62
|
+
#### payload.config.ts
|
63
|
+
|
64
|
+
```typescript
|
65
|
+
import {buildConfig} from 'payload/config'
|
66
|
+
|
58
67
|
export default buildConfig({
|
59
68
|
...,
|
60
69
|
plugins: [
|
@@ -69,18 +78,18 @@ Optionally you could use an `.env.local` file for parameters:
|
|
69
78
|
#### .env.local
|
70
79
|
|
71
80
|
```dotenv
|
72
|
-
NEXTAUTH_URL
|
73
|
-
NEXTAUTH_SECRET
|
74
|
-
ZITADEL_URL
|
75
|
-
ZITADEL_CLIENT_ID
|
76
|
-
ZITADEL_API_CLIENT_ID
|
77
|
-
ZITADEL_API_KEY_ID
|
78
|
-
ZITADEL_API_KEY
|
81
|
+
NEXTAUTH_URL=http://localhost
|
82
|
+
NEXTAUTH_SECRET=pMvElMzVrLvGL4tHyqtDlVP/90wQdxGBy94ISifi62I=
|
83
|
+
ZITADEL_URL=https://idp.zitadel.url
|
84
|
+
ZITADEL_CLIENT_ID=123456789012345678@project_name
|
85
|
+
ZITADEL_API_CLIENT_ID=123456789123456789@project_name
|
86
|
+
ZITADEL_API_KEY_ID=123456789012345678
|
87
|
+
ZITADEL_API_KEY='-----BEGIN RSA PRIVATE KEY----- ... ----END RSA PRIVATE KEY-----'
|
79
88
|
```
|
80
89
|
|
81
90
|
or use the Next.js Config file:
|
82
91
|
|
83
|
-
#### next.config.
|
92
|
+
#### next.config.js
|
84
93
|
|
85
94
|
```typescript
|
86
95
|
import {withPayload} from '@payloadcms/next/withPayload'
|
@@ -108,9 +117,36 @@ Unfortunately you need to manually create the following NextAuth.js route in you
|
|
108
117
|
### (nextauth)/api/auth/[...nextauth]/route.ts
|
109
118
|
|
110
119
|
```typescript
|
111
|
-
import {nextauthHandler} from '
|
120
|
+
import {nextauthHandler} from '@/config/zitadel-plugin'
|
112
121
|
|
113
122
|
export {nextauthHandler as GET, nextauthHandler as POST}
|
114
123
|
```
|
115
124
|
|
125
|
+
### add profile picture url to accepted Next.js assets
|
126
|
+
|
127
|
+
If you want to use the Zitadel profile picture as the avatar in PayloadCMS (`disableAvatar != true`),
|
128
|
+
you have to manually add the asset URL to the Next.js config file.
|
129
|
+
|
130
|
+
#### next.config.js
|
131
|
+
|
132
|
+
```typescript
|
133
|
+
import {withPayload} from '@payloadcms/next/withPayload'
|
134
|
+
|
135
|
+
/** @type {import('next').NextConfig} */
|
136
|
+
const nextConfig = {
|
137
|
+
images: {
|
138
|
+
remotePatterns: [
|
139
|
+
{
|
140
|
+
//protocol: new URL(process.env.ZITADEL_URL).protocol,
|
141
|
+
hostname: new URL(process.env.ZITADEL_URL).hostname,
|
142
|
+
//port: new URL(process.env.ZITADEL_URL).port,
|
143
|
+
pathname: '/assets/**'
|
144
|
+
}
|
145
|
+
]
|
146
|
+
}
|
147
|
+
}
|
148
|
+
|
149
|
+
export default withPayload(nextConfig)
|
150
|
+
```
|
151
|
+
|
116
152
|
## For an example look in this repository at the `dev` directory!
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Avatar/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAM9B,eAAO,MAAM,MAAM,UAAW;IAAE,MAAM,EAAE,OAAO,CAAA;CAAE,sBAWhD,CAAA"}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
'use client';
|
2
|
+
import * as React from 'react';
|
3
|
+
import Image from 'next/image.js';
|
4
|
+
import { DefaultAccountIcon } from '@payloadcms/ui/graphics/Account/Default';
|
5
|
+
import { useSession } from 'next-auth/react';
|
6
|
+
export const Avatar = (props)=>{
|
7
|
+
const session = useSession();
|
8
|
+
const imageUrl = session?.data?.user?.image;
|
9
|
+
return imageUrl ? /*#__PURE__*/ React.createElement("div", {
|
10
|
+
className: "avatar"
|
11
|
+
}, /*#__PURE__*/ React.createElement(Image.default, {
|
12
|
+
src: imageUrl,
|
13
|
+
alt: "Profile Picture",
|
14
|
+
fill: true
|
15
|
+
})) : /*#__PURE__*/ React.createElement(DefaultAccountIcon, {
|
16
|
+
active: props.active
|
17
|
+
});
|
18
|
+
};
|
19
|
+
|
20
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../src/components/Avatar/index.tsx"],"sourcesContent":["'use client'\n\nimport * as React from 'react'\nimport Image from 'next/image.js'\nimport {DefaultAccountIcon} from '@payloadcms/ui/graphics/Account/Default'\nimport {useSession} from 'next-auth/react'\n\n\nexport const Avatar = (props: { active: boolean }) => {\n\n const session = useSession()\n\n const imageUrl = session?.data?.user?.image\n\n return imageUrl ? (\n <div className=\"avatar\">\n <Image.default src={imageUrl} alt=\"Profile Picture\" fill/>\n </div>\n ) : <DefaultAccountIcon active={props.active}/>\n}"],"names":["React","Image","DefaultAccountIcon","useSession","Avatar","props","session","imageUrl","data","user","image","div","className","default","src","alt","fill","active"],"rangeMappings":";;;;;;;;;;;;;;;;;","mappings":"AAAA;AAEA,YAAYA,WAAW,QAAO;AAC9B,OAAOC,WAAW,gBAAe;AACjC,SAAQC,kBAAkB,QAAO,0CAAyC;AAC1E,SAAQC,UAAU,QAAO,kBAAiB;AAG1C,OAAO,MAAMC,SAAS,CAACC;IAEnB,MAAMC,UAAUH;IAEhB,MAAMI,WAAWD,SAASE,MAAMC,MAAMC;IAEtC,OAAOH,yBACH,oBAACI;QAAIC,WAAU;qBACX,oBAACX,MAAMY,OAAO;QAACC,KAAKP;QAAUQ,KAAI;QAAkBC,MAAAA;wBAExD,oBAACd;QAAmBe,QAAQZ,MAAMY,MAAM;;AAChD,EAAC"}
|
@@ -0,0 +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"}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
'use client';
|
2
|
+
import React from 'react';
|
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'
|
8
|
+
export const _LoginButton = ({ internalProviderName, externalProviderName })=>{
|
9
|
+
//currently not working
|
10
|
+
//const {t} = useTranslation<typeof translations.en, NestedKeysStripped<typeof translations.en>>()
|
11
|
+
return /*#__PURE__*/ React.createElement("div", {
|
12
|
+
style: {
|
13
|
+
display: 'flex',
|
14
|
+
justifyContent: 'center'
|
15
|
+
}
|
16
|
+
}, /*#__PURE__*/ React.createElement(Button, {
|
17
|
+
onClick: ()=>signIn(internalProviderName)
|
18
|
+
}, externalProviderName));
|
19
|
+
};
|
20
|
+
|
21
|
+
//# sourceMappingURL=button.js.map
|
@@ -0,0 +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"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/LoginButton/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,eAAO,MAAM,WAAW,mDAAkD;IACtE,oBAAoB,EAAE,MAAM,CAAC;IAC7B,oBAAoB,EAAE,MAAM,CAAA;CAC/B,4BAAkH,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../src/components/LoginButton/index.tsx"],"sourcesContent":["import React from 'react'\nimport {_LoginButton} from './button.js'\n\nexport const LoginButton = ({internalProviderName, externalProviderName}: {\n internalProviderName: string,\n externalProviderName: string\n}) => () => <_LoginButton internalProviderName={internalProviderName} externalProviderName={externalProviderName}/>"],"names":["React","_LoginButton","LoginButton","internalProviderName","externalProviderName"],"rangeMappings":";;;;;","mappings":"AAAA,OAAOA,WAAW,QAAO;AACzB,SAAQC,YAAY,QAAO,cAAa;AAExC,OAAO,MAAMC,cAAc,CAAC,EAACC,oBAAoB,EAAEC,oBAAoB,EAGtE,GAAK,kBAAM,oBAACH;YAAaE,sBAAsBA;YAAsBC,sBAAsBA;WAAuB"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Session/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAC,iBAAiB,EAAC,MAAM,OAAO,CAAA;AAGvC,eAAO,MAAM,OAAO,iBAAgB,iBAAiB,sBAAkD,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../src/components/Session/index.tsx"],"sourcesContent":["'use client'\n\nimport * as React from 'react'\nimport {SessionProvider} from 'next-auth/react'\nimport {PropsWithChildren} from 'react'\n\n\nexport const Session = ({children}: PropsWithChildren) => <SessionProvider>{children}</SessionProvider>"],"names":["React","SessionProvider","Session","children"],"rangeMappings":";;;","mappings":"AAAA;AAEA,YAAYA,WAAW,QAAO;AAC9B,SAAQC,eAAe,QAAO,kBAAiB;AAI/C,OAAO,MAAMC,UAAU,CAAC,EAACC,QAAQ,EAAoB,iBAAK,oBAACF,uBAAiBE,UAA2B"}
|
@@ -0,0 +1 @@
|
|
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"}
|
@@ -0,0 +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":["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
CHANGED
package/dist/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
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
@@ -1,11 +1,10 @@
|
|
1
|
-
import NextAuth from 'next-auth';
|
1
|
+
import NextAuth, { getServerSession } from 'next-auth';
|
2
2
|
import { signOut } from 'next-auth/react';
|
3
|
-
import { LoginButton } from './LoginButton/index.js';
|
4
3
|
import { authOptions } from './options.js';
|
5
4
|
import { zitadelStrategy } from './strategy.js';
|
6
5
|
import { translations } from './translations.js';
|
7
|
-
|
8
|
-
export const ZitadelPluginProvider = ({ authSlug = 'users', associatedIdFieldName = 'idp_id', 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,6 +22,9 @@ export const ZitadelPluginProvider = ({ authSlug = 'users', associatedIdFieldNam
|
|
23
22
|
...incomingConfig,
|
24
23
|
admin: {
|
25
24
|
...incomingConfig.admin,
|
25
|
+
...disableAvatar ? {} : {
|
26
|
+
avatar: Avatar
|
27
|
+
},
|
26
28
|
components: {
|
27
29
|
...incomingConfig.admin?.components,
|
28
30
|
afterLogin: [
|
@@ -33,6 +35,9 @@ export const ZitadelPluginProvider = ({ authSlug = 'users', associatedIdFieldNam
|
|
33
35
|
externalProviderName
|
34
36
|
})
|
35
37
|
]
|
38
|
+
],
|
39
|
+
providers: [
|
40
|
+
Session
|
36
41
|
]
|
37
42
|
}
|
38
43
|
},
|
@@ -66,6 +71,32 @@ export const ZitadelPluginProvider = ({ authSlug = 'users', associatedIdFieldNam
|
|
66
71
|
type: 'text',
|
67
72
|
unique: true,
|
68
73
|
required: true
|
74
|
+
},
|
75
|
+
{
|
76
|
+
name: 'email',
|
77
|
+
type: 'email',
|
78
|
+
admin: {
|
79
|
+
readOnly: true
|
80
|
+
},
|
81
|
+
access: {},
|
82
|
+
hooks: {
|
83
|
+
afterRead: [
|
84
|
+
async ()=>(await getServerSession())?.user?.email
|
85
|
+
]
|
86
|
+
}
|
87
|
+
},
|
88
|
+
{
|
89
|
+
name: 'name',
|
90
|
+
type: 'text',
|
91
|
+
admin: {
|
92
|
+
readOnly: true
|
93
|
+
},
|
94
|
+
access: {},
|
95
|
+
hooks: {
|
96
|
+
afterRead: [
|
97
|
+
async ()=>(await getServerSession())?.user?.name
|
98
|
+
]
|
99
|
+
}
|
69
100
|
}
|
70
101
|
],
|
71
102
|
hooks: {
|
@@ -105,12 +136,13 @@ export const ZitadelPluginProvider = ({ authSlug = 'users', associatedIdFieldNam
|
|
105
136
|
i18n: {
|
106
137
|
...incomingConfig.i18n,
|
107
138
|
translations: {
|
139
|
+
...incomingConfig.i18n?.translations,
|
108
140
|
de: {
|
109
|
-
...incomingConfig.i18n?.translations?.de
|
141
|
+
...incomingConfig.i18n?.translations?.de,
|
110
142
|
...translations.de
|
111
143
|
},
|
112
144
|
en: {
|
113
|
-
...incomingConfig.i18n?.translations?.en
|
145
|
+
...incomingConfig.i18n?.translations?.en,
|
114
146
|
...translations.en
|
115
147
|
}
|
116
148
|
}
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import NextAuth from 'next-auth'\nimport {signOut} from 'next-auth/react'\nimport {LoginButton} from './LoginButton/index.js'\nimport {authOptions} from './options.js'\nimport {zitadelStrategy} from './strategy.js'\nimport {ZitadelAuthOptionsProps, ZitadelPluginProviderType} from './types.js'\nimport {translations} from './translations.js'\n\n\nexport {LoginButton}\n\nexport const ZitadelPluginProvider: ZitadelPluginProviderType = ({\n authSlug = 'users',\n associatedIdFieldName = 'idp_id',\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 components: {\n ...incomingConfig.admin?.components,\n afterLogin: [\n ...incomingConfig.admin?.components?.afterLogin || [],\n ...(disableDefaultLoginButton ? [] : [LoginButton({\n internalProviderName,\n externalProviderName\n })])\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 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 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","signOut","LoginButton","authOptions","zitadelStrategy","translations","ZitadelPluginProvider","authSlug","associatedIdFieldName","disableLocalStrategy","disableDefaultLoginButton","internalProviderName","externalProviderName","issuerUrl","clientId","enableAPI","apiClientId","apiKeyId","apiKey","length","Error","authOptionsProps","zitadelPlugin","incomingConfig","admin","components","afterLogin","collections","map","collection","slug","auth","strategies","undefined","fields","name","type","unique","required","hooks","afterLogout","onInit","payload","existingUsers","find","limit","docs","create","data","email","password","i18n","de","en","nextauthHandler","default"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,cAAc,YAAW;AAChC,SAAQC,OAAO,QAAO,kBAAiB;AACvC,SAAQC,WAAW,QAAO,yBAAwB;AAClD,SAAQC,WAAW,QAAO,eAAc;AACxC,SAAQC,eAAe,QAAO,gBAAe;AAE7C,SAAQC,YAAY,QAAO,oBAAmB;AAG9C,SAAQH,WAAW,GAAC;AAEpB,OAAO,MAAMI,wBAAmD,CAAC,EACIC,WAAW,OAAO,EAClBC,wBAAwB,QAAQ,EAChCC,oBAAoB,EACpBC,yBAAyB,EACzBC,uBAAuB,SAAS,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Ae4B,IAAI,EAAE9C,cAAcgD,MAAM,CAAC,CAAC;4BAC9C,GAAGhD,aAAagD,EAAE;wBACtB;oBACJ;gBACJ;YACJ,CAAA;QACAC,iBAAiBtD,SAASuD,OAAO,CAACpD,YAAYkB;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,uBAAu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I,CAAC;wBACrCpB,YAAYzB;wBACZ8C,OAAO;oBACX;oBAEA,IAAIF,cAAcG,IAAI,CAAClC,MAAM,KAAK,GAAG;wBACjC,MAAM8B,QAAQK,MAAM,CAAC;4BACjBvB,YAAYzB;4BACZiD,MAAM;gCACFT,OAAO;gCACPU,UAAU;gCACV,CAACjD,sBAAsB,EAAE;4BAC7B;wBACJ;oBACJ;gBACJ;gBACAkD,MAAM;oBACF,GAAGlC,eAAekC,IAAI;oBACtBxD,cAAc;wBACV,GAAGsB,eAAekC,IAAI,EAAExD,YAAY;wBACpCyD,IAAI;4BACA,GAAGnC,eAAekC,IAAI,EAAExD,cAAcyD,EAAE;4BACxC,GAAGzD,aAAayD,EAAE;wBACtB;wBACAC,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"}
|
package/dist/options.d.ts.map
CHANGED
@@ -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,
|
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"}
|
package/dist/options.js
CHANGED
@@ -28,6 +28,11 @@ export const authOptions = ({ internalProviderName, issuerUrl, clientId })=>({
|
|
28
28
|
loginName: profile.preferred_username,
|
29
29
|
image: profile.picture
|
30
30
|
}),
|
31
|
+
userinfo: {
|
32
|
+
async request (context) {
|
33
|
+
return await context.client.userinfo(context.tokens.access_token);
|
34
|
+
}
|
35
|
+
},
|
31
36
|
clientId
|
32
37
|
}
|
33
38
|
],
|
@@ -35,8 +40,8 @@ export const authOptions = ({ internalProviderName, issuerUrl, clientId })=>({
|
|
35
40
|
session: async ({ session, token })=>({
|
36
41
|
...session,
|
37
42
|
user: {
|
38
|
-
|
39
|
-
|
43
|
+
id: token.sub,
|
44
|
+
...session.user
|
40
45
|
}
|
41
46
|
})
|
42
47
|
}
|
package/dist/options.js.map
CHANGED
@@ -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 clientId\n }\n ],\n callbacks: {\n session: async ({session, token}) => ({\n ...session,\n user: {\n
|
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"}
|
package/dist/types.d.ts
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
import { NextAuthOptions } from 'next-auth';
|
2
|
-
import { AuthStrategy } from 'payload
|
3
|
-
import { Config } from 'payload
|
2
|
+
import { AuthStrategy } from 'payload';
|
3
|
+
import { Config } from 'payload';
|
4
4
|
export type ZitadelPluginProps = {
|
5
|
+
disableAvatar?: true | undefined;
|
5
6
|
disableLocalStrategy?: true | undefined;
|
6
7
|
disableDefaultLoginButton?: true | undefined;
|
7
8
|
defaultLoginButtonTitle?: string;
|
package/dist/types.d.ts.map
CHANGED
@@ -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,
|
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,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,CAAA;AAExF,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
|
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"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "payload-zitadel-plugin",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.3",
|
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.52",
|
40
|
+
"@payloadcms/ui": "3.0.0-beta.52",
|
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.
|
45
|
-
"react": "^19.0.0-rc-
|
46
|
-
"react-dom": "^19.0.0-rc-
|
44
|
+
"payload": "3.0.0-beta.52",
|
45
|
+
"react": "^19.0.0-rc-1434af3d22-20240618",
|
46
|
+
"react-dom": "^19.0.0-rc-1434af3d22-20240618"
|
47
47
|
},
|
48
48
|
"devDependencies": {
|
49
49
|
"@swc/cli": "^0.3.12",
|
50
|
-
"@swc/core": "^1.
|
50
|
+
"@swc/core": "^1.6.1",
|
51
51
|
"@types/jsonwebtoken": "^9.0.6",
|
52
|
-
"@types/node": "^20.14.
|
52
|
+
"@types/node": "^20.14.5",
|
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.
|
56
|
+
"typescript": "^5.6.0-dev.20240618"
|
57
57
|
},
|
58
58
|
"engines": {
|
59
59
|
"node": "^22.3.0"
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"button.d.ts","sourceRoot":"","sources":["../../src/LoginButton/button.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAC,eAAe,EAAC,MAAM,gBAAgB,CAAA;AAM9C,eAAO,MAAM,YAAY,EAAE,eAa1B,CAAA"}
|
@@ -1,20 +0,0 @@
|
|
1
|
-
'use client';
|
2
|
-
import React from 'react';
|
3
|
-
import { signIn } from 'next-auth/react';
|
4
|
-
import { Button } from '@payloadcms/ui/elements';
|
5
|
-
import { useTranslation } from '@payloadcms/ui/providers/Translation';
|
6
|
-
export const _LoginButton = ({ internalProviderName, externalProviderName })=>{
|
7
|
-
const { t } = useTranslation();
|
8
|
-
return /*#__PURE__*/ React.createElement("div", {
|
9
|
-
style: {
|
10
|
-
display: 'flex',
|
11
|
-
justifyContent: 'center'
|
12
|
-
}
|
13
|
-
}, /*#__PURE__*/ React.createElement(Button, {
|
14
|
-
onClick: ()=>signIn(internalProviderName)
|
15
|
-
}, t('zitadelPlugin:signIn', {
|
16
|
-
externalProviderName
|
17
|
-
})));
|
18
|
-
};
|
19
|
-
|
20
|
-
//# sourceMappingURL=button.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../src/LoginButton/button.tsx"],"sourcesContent":["'use client'\n\nimport React from 'react'\nimport {signIn} from 'next-auth/react'\nimport {CustomComponent} from 'payload/config'\nimport {NestedKeysStripped} from '@payloadcms/translations'\nimport {Button} from '@payloadcms/ui/elements'\nimport {useTranslation} from '@payloadcms/ui/providers/Translation'\nimport {translations} from '../translations.js'\n\nexport const _LoginButton: CustomComponent = ({internalProviderName, externalProviderName}: {\n internalProviderName: string,\n externalProviderName: string\n}) => {\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,QAAO,0BAAyB;AAC9C,SAAQC,cAAc,QAAO,uCAAsC;AAGnE,OAAO,MAAMC,eAAgC,CAAC,EAACC,oBAAoB,EAAEC,oBAAoB,EAGxF;IACG,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 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/LoginButton/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,eAAO,MAAM,WAAW,mDAAkD;IACtE,oBAAoB,EAAE,MAAM,CAAC;IAC7B,oBAAoB,EAAE,MAAM,CAAA;CAC/B,4BAAkH,CAAA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../src/LoginButton/index.tsx"],"sourcesContent":["import React from 'react'\nimport {_LoginButton} from './button.js'\n\nexport const LoginButton = ({internalProviderName, externalProviderName}: {\n internalProviderName: string,\n externalProviderName: string\n}) => () => <_LoginButton internalProviderName={internalProviderName} externalProviderName={externalProviderName}/>"],"names":["React","_LoginButton","LoginButton","internalProviderName","externalProviderName"],"rangeMappings":";;;;;","mappings":"AAAA,OAAOA,WAAW,QAAO;AACzB,SAAQC,YAAY,QAAO,cAAa;AAExC,OAAO,MAAMC,cAAc,CAAC,EAACC,oBAAoB,EAAEC,oBAAoB,EAGtE,GAAK,kBAAM,oBAACH;YAAaE,sBAAsBA;YAAsBC,sBAAsBA;WAAuB"}
|
File without changes
|
File without changes
|