title: TypeError: resolver is not a function
body: <p>I am attempting to create a basic post on click in my NextJS app to a MongoDB database. The issue i am getting is <code>TypeError: resolver is not a function</code>. I understand it might be a syncronicity issue but for the life of me I cannot figure out where.</p>
  
  <p>Stack used: NextJS, Axios, Mongoose.</p>
  
  <p>Component code snippet calling axios:</p>
  
  <p><em>i know the states are updating so i am putting only the snippet that handles the request</em></p>
  
  <pre><code>  handleSubmit = async (e: any) =&gt; {
      e.preventDefault();
  
      await axios
        .post('/api/roomSession', {
          roomName: this.state.roomName,
          teamName: this.state.teamName
        })
        .then((response: any) =&gt; console.log('axios call reached', response))
        .catch((error: any) =&gt; console.log('---- error! ----', error));
    };
  
  [...]
  &lt;button onClick={this.handleSubmit}&gt;Create&lt;/button&gt;
  [...]
  </code></pre>
  
  <p>NextJS API file:</p>
  
  <pre><code>import { newSession } from '../../packages/backend/mongo/connection';
  
  const apiNewSession = async (roomName, teamName) =&gt; {
    await newSession(teamName, roomName);
  };
  
  export default apiNewSession();
  </code></pre>
  
  <p>Mongoose file:</p>
  
  <pre><code>const mongoose = require('mongoose');
  
  mongoose
    .connect(
      'mongodbconnection',
      { useNewUrlParser: true, useUnifiedTopology: true }
    )
    .then(() =&gt; {
      console.log('connected to mongoDB');
    })
    .catch(err =&gt; console.error('Connection failed: ', err));
  
    const sessionSchema = new mongoose.Schema({
      teamName: String,
      roomName: String
    });
  
  const Session = mongoose.model.tests || mongoose.model('tests', sessionSchema);
  
  export const newSession = async (teamName, roomName) =&gt; {
    const session = new Session({
      teamName,
      roomName
    });
    const result = await session.save();
    mongoose.connection.close();
  };
  </code></pre>
  
  <p><em>Some extra info on the strange behaviour: When first time called, the code throws the aformentioned error but manages to reach the mongoDB connection and creates an EMPTY entry inside the collection (only _id, and _v).
  Upon second attempt, only the error is thrown.</em> </p>