OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Request.formData: Could not parse content as FormData (ASTRO - FIREBASE)

  • Thread starter Thread starter Geofrey Njavike
  • Start date Start date
G

Geofrey Njavike

Guest
I'm writing a web app with connection to firebase. But i'm getting an error.

Need assistance to check the error and an alternative if any.

Server Code.

Code:
`import type { APIRoute } from "astro";
import { supabase } from "../../../lib/supabase";

export const POST: APIRoute = async ({ request, redirect }) => {
  const formData = await request.formData();
  const email = formData.get("email")?.toString();
  const password = formData.get("password")?.toString();

  console.log(email);

  if (!email || !password) {
    return new Response("Email and password are required", { status: 400 });
  }

  const { error } = await supabase.auth.signUp({
    email,
    password,
  });

  if (error) {
    return new Response(error.message, { status: 500 });
  }

  return redirect("/signin");
};`

Client code.

Code:
---
import Layout from "../../layouts/mainLayoout.astro"
---
<Layout title="Register">
  <h1>Register</h1>
  <p>Already have an account? <a href="/signin">Sign in</a></p>
  <form action="/api/auth/register" method="post" enctype="application/x-www-form-urlencoded">
    <label for="email">Email</label>
    <input type="email" name="email" id="email" />
    <label for="password">Password</label>
    <input type="password" name="password" id="password" />
    <button type="submit">Register</button>
  </form>
</Layout>`

Beloe is the error that i'm getting.

Error

Request.formData: Could not parse content as FormData

<p>I'm writing a web app with connection to firebase. But i'm getting an error.</p>
<p>Need assistance to check the error and an alternative if any.</p>
<p>Server Code.</p>
<pre><code>`import type { APIRoute } from "astro";
import { supabase } from "../../../lib/supabase";

export const POST: APIRoute = async ({ request, redirect }) => {
const formData = await request.formData();
const email = formData.get("email")?.toString();
const password = formData.get("password")?.toString();

console.log(email);

if (!email || !password) {
return new Response("Email and password are required", { status: 400 });
}

const { error } = await supabase.auth.signUp({
email,
password,
});

if (error) {
return new Response(error.message, { status: 500 });
}

return redirect("/signin");
};`
</code></pre>
<p>Client code.</p>
<pre><code>
---
import Layout from "../../layouts/mainLayoout.astro"
---
<Layout title="Register">
<h1>Register</h1>
<p>Already have an account? <a href="/signin">Sign in</a></p>
<form action="/api/auth/register" method="post" enctype="application/x-www-form-urlencoded">
<label for="email">Email</label>
<input type="email" name="email" id="email" />
<label for="password">Password</label>
<input type="password" name="password" id="password" />
<button type="submit">Register</button>
</form>
</Layout>`
</code></pre>
<p>Beloe is the error that i'm getting.</p>
<p>Error</p>
<p>Request.formData: Could not parse content as FormData</p>
 
Top