npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

payload-zitadel-plugin

v0.5.11

Published

plugin for Payload CMS, which enables authentication via Zitadel IdP

Readme

payload-zitadel-plugin

NPM

a plugin for Payload CMS (v3), which enables authentication via Zitadel IdP

The default use case is to fully replace PayloadCMS Auth with Zitadel. Thus, the user collection in PayloadCMS becomes just a shadow of the information in Zitadel.

Install

pnpm add [email protected]

Configuration

Initialize the plugin in the Payload config file. Change the parameters to connect to your Zitadel instance.

The cleanest way to use this plugin is just to set the ZITADEL_URL and ZITADEL_CLIENT_ID environment variables, set up the next.config.ts as described down below and then add zitadelPlugin() without further configuration to the plugin list.

payload.config.ts

import {buildConfig} from 'payload'
import {zitadelPlugin} from 'payload-zitadel-plugin'


export default buildConfig({
    ...,
    plugins: [
        zitadelPlugin({
            // URL of your Zitadel instance
            // if not provided, it will look for the ZITADEL_URL environment variable
            // issuerUrl: 'https://idp.zitadel.url',

            // in Zitadel create a new App->Web->PKCE in your project, then copy the Client ID
            // DO NOT FORGET to add '{http://localhost with development mode on or https://your-domain.tld}/api/users/callback'
            // to the allowed redirect URIs and ALSO to the post logout redirect URIs
            // if not provided, it will look for the ZITADEL_CLIENT_ID environment variable
            // clientId: '123456789012345678@project_name',

            // change field names, field labels and also hide them if wanted
            /* 
            fieldConfig: {
                image: {
                    name: 'idp_image',
                    label: 'some custom label'
                }
            }
            */

            // set the name of the CustomStrategy in PayloadCMS - usually not necessary
            // strategyName: 'zitadel'

            /* 
            avatar: {
                // set to true if you do not want to use the Zitadel Profile Picture as the Avatar
                disable: true
            }
            */


            /* 
            loginButton: {
                // set to true if you want to use your own custom login button
                disable: true,
                
                // interpolation text for the Login Button - "sign in with ..."
                label: 'Zitadel'
            }
            */

            // if you want to manually control what happens after a successful login
            // afterLogin: (req) => NextResponse.redirect('...')

            // if you want to manually control what happens after a successful logout
            // afterLogout: (req) => NextResponse.redirect('...')

            // following properties are only needed if you want to authenticate clients 
            // (e.g. a mobile app or a external service) for the API
            // if the users are just visiting the CMS via a browser you can ignore all of them
            // otherwise create in Zitadel a new App->API->JWT and create a new key
            // download the JSON file and put the content in the jwt parameter
            // if not provided it will look for the ZITADEL_API_JWT environment variable
            /* 
            api: {
                type: 'jwt'
                jwt: {
                    keyId: '123456789123456789',
                    key: '-----BEGIN RSA PRIVATE KEY----- ... ----END RSA PRIVATE KEY-----',
                    appId: '123456789123456789',    
                    clientId: '123456789123456789'
                }
            }
            */

            // you can also use basic auth instead of JWT
            // create a new App->API->Basic and save the Client Id and Client Secret
            // if not provided it will look for the ZITADEL_API_CLIENT_ID environment variable
            // make sure you have the ZITADEL_API_JWT environment variable unset as JWT will have priority
            /* 
            api: {
                type: 'basic'
                clientId: '123456789123456789',
                clientSecret: '...'
            }
            */
        })
    ],
    ...
})

Optionally you could use an .env.local file for parameters:

.env.local

ZITADEL_URL=https://idp.zitadel.url
ZITADEL_CLIENT_ID=123456789123456789
# if you use basic auth
ZITADEL_API_CLIENT_ID: '123456789123456789',
ZITADEL_API_CLIENT_SECRET: '...',
# if you use JWT auth
ZITADEL_API_JWT='{"type":"application","keyId":"123456789123456789","key":"-----BEGIN RSA PRIVATE KEY-----\n ... \n-----END RSA PRIVATE KEY-----\n","appId":"123456789123456789","clientId":"123456789123456789"}'

or use the Next.js Config file:

next.config.ts

import {withPayload} from '@payloadcms/next/withPayload'

export default withPayload({
    ...,
    env: {
        ZITADEL_URL: 'https://idp.zitadel.url',
        ZITADEL_CLIENT_ID: '123456789123456789',
        // if you use basic auth
        ZITADEL_API_CLIENT_ID: '123456789123456789',
        ZITADEL_API_CLIENT_SECRET: '...',
        // if you use JWT auth
        ZITADEL_API_JWT = '{"type":"application","keyId":"123456789123456789","key":"-----BEGIN RSA PRIVATE KEY-----\n ... \n-----END RSA PRIVATE KEY-----\n","appId":"123456789123456789","clientId":"123456789123456789"}'
    },
    ...
})

Also, every environment variable has a <ENV_NAME>_FILE variant if you want to load the data via Docker secrets. For instance, you could set the ZITADEL_API_JWT_FILE=/run/secrets/zitadel_api_jwt environment variable and provide a Docker secret zitadel_api_jwt via Docker Compose. Please keep in mind that for the <ENV_NAME>_FILE variant to be used, the <ENV_NAME> variable needs to be unset (as the base variable takes precedence).

further configuration

If you want to use the Zitadel profile picture as the avatar in PayloadCMS, you have to manually add the asset URL to the Next.js config file.

For a proper logout you have to add the end_session redirect.

Also, if you want to automatically redirect to Zitadel without asking the user to click on the login button, you have to add the redirect manually to the Next.js config file.

next.config.ts

import {withPayload} from '@payloadcms/next/withPayload'

export default withPayload({
    ...,

    // if Avatar enabled:
    // allow loading assets like profile pictures from Zitadel
    images: {
        remotePatterns: [
            {
                // protocol: new URL(process.env.ZITADEL_URL).protocol,
                hostname: new URL(process.env.ZITADEL_URL).hostname,
                // port: new URL(process.env.ZITADEL_URL).port,
                pathname: '/assets/**'
            }
        ]
    },

    async redirects() {
        return [
            // for proper logout
            {
                // all paths, that do not start with 'api'
                // it is important to ignore the Payload API routes!
                source: '/:path((?!api).*)',
                destination: '/api/users/end_session?redirect=/:path*',
                has: [
                    {
                        type: 'cookie',
                        key: 'zitadel_logout'
                    }
                ],
                permanent: false
            },
            // optional: enable auto-redirect to Zitadel login page if not logged in
            {
                // all paths that start with 'admin' or 'profile'
                // you could replace 'profile' with 'app' or some other protected route
                source: '/:path((?:admin|profile).*)',
                destination: '/api/users/authorize?redirect=/:path*',
                missing: [
                    {
                        type: 'cookie',
                        key: 'zitadel_id_token'
                    }
                ],
                permanent: false
            }
        ]
    },

    ...

})

For an example look in this repository at the dev directory!