Skip to content

[BUG] - support to formbody is missing #34

@AceCodePt

Description

@AceCodePt

I have the following code:

const defineRoutes: DefineFastifyRoutes = (fastify) => {
 fastify.register(import("@fastify/formbody"));
}

I ran:
pnpm build
node ./dist/server/entry.mjs

This code seems to throw the follwoing:

{"statusCode":500,"error":"Internal Server Error","message":"Response body object should not be disturbed or locked"}

When I had a post request to:

import {
  serverRouteClient,
  serverRouteClientServiceRole,
} from "@supabase/instances";
import type { APIRoute } from "astro";
import { z } from "zod";

export const POST: APIRoute = async ({ request, cookies, url, redirect }) => {
  console.log("signup");
  const supabase = serverRouteClient(cookies);

  const body = await request
    .formData()
    .then(Object.fromEntries)
    .then(
      z.object({
        email: z.string().email(),
        password: z.string(),
        passwordConfirmation: z.string(),
      }).parseAsync,
    );

  if (body.password != body.passwordConfirmation) {
    throw new Error("Confirmation password didn't match the actual password");
  }

  const res = await supabase.auth.signUp({
    email: body.email,
    password: body.password,
    options: {
      emailRedirectTo: `${url.origin}/auth/callback`,
    },
  });

  if (res.error) {
    return new Response(res.error.message, { status: res.error.status });
  }
  if (!res.data.user?.id) {
    return new Response("Failed to create a user", { status: 500 });
  }
  
  return redirect("/");
};

I have the following configuration:

import { defineConfig } from "astro/config";
import react from "@astrojs/react";
import tailwind from "@astrojs/tailwind";
import fastify from "@matthewp/astro-fastify";

// https://astro.build/config
export default defineConfig({
  integrations: [react(), tailwind()],
  output: "server",
  adapter: fastify({
    entry: new URL("./server-entry.ts", import.meta.url),
  }),
  server: {
    port: +(process.env.PORT || 4321),
  },
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions