what is causing Multipart/form-data error on loopback4?

Viewed 55

I am having this error while posting the login information using the form data method. I am new to loopback I can't understand what exactly is causing the error please help me

{
  "error": {
    "statusCode": 415,
    "name": "UnsupportedMediaTypeError",
    "message": "Content-type multipart/form-data; boundary=----WebKitFormBoundaryvZT2m13MPBuh9hJY is not supported.",
    "code": "UNSUPPORTED_MEDIA_TYPE"
  }
}

here is the code of my controller file

USER.Controller

@post('/auth/login', {
    responses: {
      '200': {
        description: 'Token',
        content: {
          'application/json': {
            schema: {
              type: 'object',
              properties: {
                token: {
                  type: 'string',
                },
              },
            },
          },
        },
      },
    },
  })
  async login(
    @requestBody(CredentialsRequestBody) credentials: Credentials,
  ): Promise<{token: string}> {
    const user = await this.userService.verifyCredentials(credentials);
    const userProfile = this.userService.convertToUserProfile(user);
    const token = await this.jwtService.generateToken(userProfile);

    return {token};
  }

CredentialsReq

export const CredentialsRequestBody: RequestBodyObject = {
  description: 'The input of login function',
  required: true,
  content: {
    'multipart/form-data' : {schema: CredentialsSchema},
  },
};

CredentialsSchema

const CredentialsSchema: SchemaObject = {
  type: 'object',
  required: ['email', 'password'],
  properties: {
    email: {
      type: 'string',
      format: 'email',
    },
    password: {
      type: 'string',
      minLength: 8,
    }
  },
};
0 Answers
Related