Skip to content
Discussion options

You must be logged in to vote

The way you've outlined with fetching /api/auth/emailAvailable actually slows down the endpoint, instead you can import the function that you were going to execute.

Eg:

// pages/api/auth/emailAvailable.js

export function emailAvailable(email) {
  // Just an example
  return db.find(email).length > 0
}

export default (req, res) => {
  return res.json({ available: emailAvailable(req.body.email) })
}
// pages/api/auth/register.js
import {emailAvailable} from './emailAvailable'

export default (req, res) => {
  const available = emailAvailable(req.body.email)
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ajones55555
Comment options

ajones55555 Mar 21, 2020
Collaborator Author

Answer selected by timneutkens
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants