Query and save user to DB after login Nextjs-Auth0

Hi, I am using the nextjs-auth0 SDK.

How/where after login should I be checking if the user exists in my external DB, and to create the user in the external DB if they do not exist?

I attempted to use afterCallback, but am unsure how to make it work.

const afterCallback = async (req, res, session, state) => {
  console.log("session info: ", session.user);
  console.log("state info: ", state);

  // check if user exists in a DB
   const userExists = await client.query({ CUSTOMER_QUERY });

    // if not, create user in postgres DB


  return session;
};

export default handleAuth({
  async login(req, res) {
    try {
      await handleLogin(req, res, {
        returnTo: "/dashboard",
      });
    } catch (error) {
      res.status(error.status || 400).end(error.message);
    }
  },
  async callback(req, res) {
    try {
      await handleCallback(req, res, { afterCallback });
    } catch (error) {
      res.status(error.status || 500).end();
    }
  },
});

Hey there!

If I were you in order to handle that most effectively I would discuss it directly with the SDK maintainers through a GitHub issue. Just make sure to provide the same context there as here and as soon as you open it please share the link to it here so we can ping them. Thank you!