Create login and register function to another application

Hello, i am trying to build login and register function to my application. The software i use for develop my application only can connect with database. So, i use http endpoint mongodb. But I shown error when i am trying to connect with my application. I am very new to this. Anyone can help.

This is my function for auth in the http endpoints:

 exports = async function(loginPayload) {
  // Get a handle for the app.users collection
  const users =
  const username = loginPayload.toString();

  const user = await users.findOne( {"userData.username": username} );

  if (user) {
    // If the user document exists, return its unique ID
    return user._id.toString();
  } else {
    // If the user document does not exist, create it and then return its unique ID
    const newDocument = {
      "userData": {
        "username": username,
        "email": "",
        "password":" "
    const result = await users.insertOne(newDocument);
    return result.insertedId.toString();

and this is the error message i got:

 {"error":"SyntaxError: invalid character 'u' looking for beginning of value","error_code":"FunctionExecutionError","link":""}