Skip to content

feat: add support for custom verification token generation #13152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ochrstn
Copy link

@ochrstn ochrstn commented Jul 13, 2025

What?

This PR adds the ability for developers to define custom verification token generation logic in PayloadCMS authentication. It introduces a new optional generateVerificationToken function that can be configured in the auth.verify settings.

Why?

Currently, verification tokens are generated using a hardcoded crypto.randomBytes(20).toString('hex')approach. This limitation prevents developers from:

  • Implementing custom token formats or domain-specific token patterns
  • Integrating with external token services
  • Meeting specific security or compliance requirements

How?

Check for custom token generator. Supports both synchronous and asynchronous custom token generators. Maintains backward compatibility by falling back to default crypto.randomBytes(20).toString('hex').

Usage Example:

export const Users: CollectionConfig = {
  slug: 'users',
  auth: {
    verify: {
      generateVerificationToken: ({ req, user }) => {
        return `custom-${user.id}-${Date.now()}`
      },
    },
  },
  // ...
}

@ochrstn ochrstn changed the title feat(auth): add support for custom verification token generation feat: add support for custom verification token generation Jul 13, 2025
@ochrstn ochrstn force-pushed the feat/custom-validation-token branch from 06e6dda to d2ee420 Compare July 13, 2025 16:46
@ochrstn ochrstn marked this pull request as ready for review July 13, 2025 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant