Skip to content

Local API verifyEmail throws an error instead of returning false #14682

Open

Description

@roydigerhund

Documentation Issue

In the docs https://payloadcms.com/docs/local-api/overview#verify it is stated that the result of await payload.verifyEmail "will be a boolean representing success or failure".

// Returned result will be a boolean representing success or failure
const result = await payload.verifyEmail({
  collection: 'users', // required
  token: 'afh3o2jf2p3f...', // the token saved on the user as `_verificationToken`
})

But while using this method I figured it is never returning false but throwing an error instead. This can be a problem if someone (like me 😄) expects a boolean value for a graceful handling of a false case.

Additional Details

Instead of changing the documentation I would rather propose to change the method to create the behavior described in the docs.
The proposal would be to change this line when a user with the verify token wasn't found verifyEmail.ts L46

    // Before
    if (!user) {
      throw new APIError('Verification token is invalid.', httpStatus.FORBIDDEN)
    }

    // After
    if (!user) {
      return false
    }

The same problem might exist for REST and GraphQL as well.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions