sveltejs / realworld

SvelteKit implementation of the RealWorld app
https://realworld.svelte.dev
MIT License
2.24k stars 353 forks source link

POST requests to register and login failing. #101

Closed davidbogue closed 2 years ago

davidbogue commented 2 years ago

Using the latest versions of SvelteKit and the Adapters, the request object in POST APIs does not successfully extract the request body.

While debugging I noticed the request.body is not an object with the form fields, but is instead a Readable stream.

For example the existing register.js POST api returns an error that email is missing as it is written now:

export async function post({ request }) {
    const user = request.body;

The code works if it is changed to read the stream and parse the JSON into an object:

export async function post({ request }) {
    const user = JSON.parse(request.body.read());

I had the same issue in a personal project with recent SvelteKit changes, so the issue may actually be in SvelteKit.

This occurs with the latest realworld code: "node_modules/@sveltejs/kit": "version": "1.0.0-next.240" "@sveltejs/adapter-netlify": "version": "1.0.0-next.42" "@sveltejs/adapter-vercel": "version": "1.0.0-next.39"

benmccann commented 2 years ago

fixed here: https://github.com/sveltejs/realworld/commit/9204725d05b04c18ce4f0d54c2c75b5bb6e0472b