#Astro Supabase Auth on Vercel

1 messages · Page 1 of 1 (latest)

wanton oriole
#

astro.config
import { defineConfig } from 'astro/config';
import vercel from "<@&1055234544183287879>/vercel/serverless";
import tailwindcss from '@tailwindcss/vite';

export default defineConfig({
output: "server",
adapter: vercel(),
vite: {
plugins: [tailwindcss()]
}
});
api/auth/register
// With output: 'static' configured:
// export const prerender = false;
import type { APIRoute } from "astro";
import { supabase } from "../../../lib/supabase";

export const POST: APIRoute = async ({ request, redirect }) => {
const formData = await request.formData();

const username = formData.get("name")?.toString().trim();
const email = formData.get("email")?.toString().trim();
const password = formData.get("password")?.toString();

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

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

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

return redirect("/signin");

};

on vercel not publick

Хост astro-auth-payments.vercel.app зараз не може обробити цей запит.
HTTP ERROR 500

frozen latchBOT
#

Hi @wanton oriole. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Looking at your setup, there's a likely issue with your adapter import path.

The Problem: Adapter Import

You're importing from @astrojs/vercel/serverless, but the current @astrojs/vercel package (v9+) no longer uses the /serverless entrypoint — it's just a single unified package. [Vercel adapter]

Change your astro.config.mjs from:

import vercel from "@astrojs/vercel/serverless";

To:

import vercel from '@astrojs/vercel';

Your full config should look like:

import { defineConfig } from 'astro/config';
import vercel from '@astrojs/vercel';
import tailwindcss from '@tailwindcss/vite';

export default defineConfig({
  output: "server",
  adapter: vercel(),
  vite: {
    plugins: [tailwindcss()]
  }
});

Your API Route

Since you have output: "server", all routes are server-rendered by default, so you do not need export const prerender = false in your API routes. Your register.ts logic looks correct otherwise. [auth server endpoints]

Deployment

After fixing the adapter import, rebuild and redeploy:

astro build
vercel deploy --prebuilt

[Vercel usage]

The HTTP 500 error on Vercel is most likely caused by the incorrect adapter entrypoint, which would cause the build/runtime to fail. Fixing the import should resolve it.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@wanton oriole Kapa.ai is still learning and improving, please let me know how I did by reacting below.

wanton oriole
#

@frozen latch This Serverless Function has crashed.

Your connection is working correctly.

Vercel is working correctly.

500: INTERNAL_SERVER_ERROR
Code: FUNCTION_INVOCATION_FAILED
ID: lhr1::nxgl9-1772452860517-7ff962a25bea

frozen latchBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

The FUNCTION_INVOCATION_FAILED error means your Vercel Serverless Function is crashing at runtime. Based on the knowledge sources, here are the most likely causes and fixes:

1. Verify the Adapter Import

As mentioned in the previous response, make sure your astro.config.mjs uses the correct import:

import { defineConfig } from 'astro/config';
import vercel from '@astrojs/vercel';
import tailwindcss from '@tailwindcss/vite';

export default defineConfig({
  output: "server",
  adapter: vercel(),
  vite: {
    plugins: [tailwindcss()]
  }
});

[Vercel adapter]

2. Check for Missing Files

If your function relies on files (e.g., config files, data files) that aren't being bundled, you can force them to be included using includeFiles:

adapter: vercel({
  includeFiles: ['./src/lib/supabase.ts'],
})

[includeFiles option]

3. Check Function Timeout

If your Supabase calls are timing out, you can extend the max duration:

adapter: vercel({
  maxDuration: 60
})

[maxDuration option]

4. Verify Environment Variables

Make sure your SUPABASE_URL and SUPABASE_ANON_KEY environment variables are set in your Vercel project settings (not just your local .env file). Vercel does not automatically read your local .env file — you need to add them via the Vercel dashboard under Settings > Environment Variables. [Supabase setup]

#

Missing environment variables on Vercel is a very common cause of FUNCTION_INVOCATION_FAILED errors with Supabase integrations.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@wanton oriole Kapa.ai is still learning and improving, please let me know how I did by reacting below.

wanton oriole
#

@frozen latch
import { defineConfig } from 'astro/config';
import vercel from '<@&1055234544183287879>/vercel';
import tailwindcss from '@tailwindcss/vite';

export default defineConfig({
output: "server",
adapter: vercel({
includeFiles: ['./src/lib/supabase.ts'],
}),
vite: {
plugins: [tailwindcss()]
}
});

This Serverless Function has crashed.

Your connection is working correctly.

Vercel is working correctly.

500: INTERNAL_SERVER_ERROR
Code: FUNCTION_INVOCATION_FAILED
ID: lhr1::w9wgr-1772452984200-275913f90aba

If you are a visitor, contact the website owner or try again later.

frozen latchBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

The adapter import looks correct now, and includeFiles is configured. Since the crash persists, the most likely remaining cause is missing environment variables on Vercel.

Most Likely Cause: Missing Environment Variables

Your src/lib/supabase.ts uses import.meta.env.SUPABASE_URL and import.meta.env.SUPABASE_ANON_KEY. These must be explicitly added in your Vercel project dashboard — your local .env file is not deployed to Vercel. [Supabase setup]

Steps to fix:

  1. Go to your project in the Vercel Dashboard
  2. Navigate to Settings > Environment Variables
  3. Add both:
    • SUPABASE_URL = your Supabase project URL
    • SUPABASE_ANON_KEY = your Supabase anonymous key
  4. Redeploy your project after adding the variables (Vercel requires a new deployment for env var changes to take effect)

Also Check: Function Timeout

If the Supabase client is hanging (e.g., network issues reaching Supabase), you can extend the timeout:

import { defineConfig } from 'astro/config';
import vercel from '@astrojs/vercel';
import tailwindcss from '@tailwindcss/vite';

export default defineConfig({
  output: "server",
  adapter: vercel({
    includeFiles: ['./src/lib/supabase.ts'],
    maxDuration: 60,
  }),
  vite: {
    plugins: [tailwindcss()]
  }
});

[maxDuration option]

The knowledge sources do not provide further specific debugging steps for FUNCTION_INVOCATION_FAILED, but missing environment variables on Vercel is the most common cause of this error when Supabase is involved.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@wanton oriole Kapa.ai is still learning and improving, please let me know how I did by reacting below.

wanton oriole
#

@frozen latch when add server and adapter vercel has error This Serverless Function has crashed.

// @ts-check
import { defineConfig } from 'astro/config';
import vercel from '<@&1055234544183287879>/vercel';
import tailwindcss from '@tailwindcss/vite';

export default defineConfig({
output: "server",
adapter: vercel({
maxDuration: 60,
}),
vite: {
plugins: [tailwindcss()]
}
});

frozen latchBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

Based on the knowledge sources available, I can confirm your astro.config.mjs configuration looks correct for deploying to Vercel with on-demand rendering. [Vercel adapter]

The knowledge sources do not provide specific runtime crash debugging steps beyond what's already been covered in this conversation. However, since the config itself is valid, the crash is almost certainly a runtime environment issue, not a configuration one.

Checklist to Resolve

  1. Environment Variables on Vercel — This remains the most likely cause. Confirm in your Vercel Dashboard under Settings > Environment Variables that all required variables (e.g., SUPABASE_URL, SUPABASE_ANON_KEY) are present and set for the correct environment (Production/Preview).

  2. Redeploy after adding env vars — Vercel requires a fresh deployment after adding or changing environment variables.

  3. Check Vercel Function Logs — In your Vercel Dashboard, go to your project → Deployments → click the latest deployment → Functions tab. This will show the actual error/stack trace from the crash, which will pinpoint the exact cause.

The knowledge sources do not contain further information to diagnose FUNCTION_INVOCATION_FAILED beyond these steps. The actual error message in the Vercel function logs is what you need to identify the root cause.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@wanton oriole Kapa.ai is still learning and improving, please let me know how I did by reacting below.

wanton oriole
#

@frozen latch there log
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/var/task/dist/server/entry.mjs' imported from /opt/rust/nodejs.js
at finalizeResolution (node:internal/modules/esm/resolve:280:11)
at moduleResolve (node:internal/modules/esm/resolve:865:10)
at moduleResolveWithNodePath (node:internal/modules/esm/resolve:989:14)
at defaultResolve (node:internal/modules/esm/resolve:1032:79)
at #cachedDefaultResolve (node:internal/modules/esm/loader:731:20)
at ModuleLoader.resolve (node:internal/modules/esm/loader:708:38)
at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:310:38)
at onImport.tracePromise.proto (node:internal/modules/esm/loader:664:36)
at TracingChannel.tracePromise (node:diagnostics_channel:350:14)
at ModuleLoader.import (node:internal/modules/esm/loader:663:21) {
code: 'ERR_MODULE_NOT_FOUND',
url: 'file:///var/task/dist/server/entry.mjs'
}
Node.js process exited with exit status: 1. The logs above can help with debugging the issue.

frozen latchBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

The error is clear:

Cannot find module '/var/task/dist/server/entry.mjs'

This means the build output is not being included in the Vercel deployment. The serverless function is looking for dist/server/entry.mjs but it doesn't exist in the deployed package.

Fix: Use vercel deploy --prebuilt or let Vercel build remotely

You have two options:

Option A: Let Vercel build on their servers (recommended)

Don't run astro build locally and then deploy. Instead, push your code to Git and let Vercel handle the build automatically via its Git integration. Vercel will detect Astro and run the build for you. [Website UI deployment]

Option B: Build locally and deploy with --prebuilt

If you want to build locally, you must use the --prebuilt flag so Vercel uses your local build output:

astro build
vercel deploy --prebuilt

[Vercel usage]

Running vercel deploy without --prebuilt after a local build causes Vercel to ignore your dist/ folder and attempt its own build — or deploy without the build output — resulting in the missing entry.mjs error.

This is the root cause of all the FUNCTION_INVOCATION_FAILED errors you've been seeing.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@wanton oriole Kapa.ai is still learning and improving, please let me know how I did by reacting below.

wanton oriole
#

@frozen latch no still error Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/var/task/dist/server/entry.mjs' imported from /opt/rust/nodejs.js

frozen latchBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

The error persists, which means the build output is still not reaching Vercel correctly. Let me clarify the two scenarios:

If deploying via Git (Vercel Dashboard)

Make sure you are not committing your dist/ folder to Git (it should be in .gitignore). Vercel needs to run astro build itself during deployment. Check your Vercel project settings to confirm:

  • Build Command is set to astro build (or npm run build)
  • Output Directory is set to dist
  • Framework Preset is detected as Astro

You can verify/override these in your Vercel Dashboard under Settings > General > Build & Development Settings.

If deploying via CLI

You must run both commands in sequence:

astro build
vercel deploy --prebuilt

Using vercel deploy without --prebuilt will not include your local dist/ folder. [Vercel usage]

Also check: vercel.json

If you have a vercel.json file in your project, it may be overriding the build command or output directory incorrectly. Review it and ensure it doesn't conflict with Astro's build output. [project config]


The knowledge sources do not provide further specific debugging steps for this error beyond build/deployment configuration. If the above steps don't resolve it, I'd recommend checking the Vercel build logs (not just the function logs) to see if astro build is actually completing successfully during deployment.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@wanton oriole Kapa.ai is still learning and improving, please let me know how I did by reacting below.

wanton oriole
#

@frozen latch generate vercel.json

frozen latchBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

The knowledge sources do not contain enough information to generate a specific vercel.json configuration for your Astro project. The documentation only briefly mentions that vercel.json can be used to override Vercel's default behavior (e.g., attaching headers), but does not provide specific content or examples for it. [project config]

For your specific issue (entry.mjs not found), a vercel.json is unlikely to be the right fix. Instead, I'd recommend:

  1. Let Vercel build automatically by pushing to Git and ensuring your Vercel project settings have:

    • Build Command: astro build (or npm run build)
    • Output Directory: dist
  2. Or deploy with prebuilt output:

    astro build
    vercel deploy --prebuilt
    

    [Vercel usage]

For vercel.json specifics, please refer to Vercel's official project configuration documentation directly, as that is outside the scope of Astro's documentation.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@wanton oriole Kapa.ai is still learning and improving, please let me know how I did by reacting below.

wanton oriole
#

@frozen latch show correct vercel.json

frozen latchBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

The knowledge sources do not contain a vercel.json example or template for Astro projects. The Astro documentation only mentions that vercel.json can be used to override Vercel's default behavior and configure additional settings, but provides no specific content for it. [project config]

For a correct vercel.json, please refer directly to Vercel's official project configuration documentation, as this is outside the scope of Astro's documentation.

That said, based on the conversation so far, your entry.mjs not found error is a build/deployment issue, not something a vercel.json would fix. The recommended solutions remain:

Option A – Git-based deployment (recommended):
Push to Git and let Vercel build automatically with:

  • Build Command: astro build or npm run build
  • Output Directory: dist

Option B – CLI with prebuilt flag:

astro build
vercel deploy --prebuilt

[Vercel usage]

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@wanton oriole Kapa.ai is still learning and improving, please let me know how I did by reacting below.

wanton oriole
#

@frozen latch vercel not work with astro node.js error
import { defineConfig } from 'astro/config';
import vercel from "<@&1055234544183287879>/vercel/serverless";
import tailwindcss from '@tailwindcss/vite';

export default defineConfig({
output: "server",
adapter: vercel({
maxDuration: 60,
}),
vite: {
plugins: [tailwindcss()]
}
});

frozen latchBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

Your import path is the problem. You're importing from @astrojs/vercel/serverless, but the current @astrojs/vercel package no longer uses that sub-path entrypoint — it's a single unified package now.

Fix your import:

import { defineConfig } from 'astro/config';
import vercel from '@astrojs/vercel'; // ✅ correct
import tailwindcss from '@tailwindcss/vite';

export default defineConfig({
  output: "server",
  adapter: vercel({
    maxDuration: 60,
  }),
  vite: {
    plugins: [tailwindcss()]
  }
});

[Vercel adapter]

This has been the issue since the start of this conversation. The @astrojs/vercel/serverless entrypoint no longer exists in the current version of the adapter, which would cause the build to fail and result in the entry.mjs not found error at runtime.

After fixing the import, redeploy by pushing to Git and letting Vercel build automatically, or run:

astro build
vercel deploy --prebuilt

[Vercel usage]

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@wanton oriole Kapa.ai is still learning and improving, please let me know how I did by reacting below.

wanton oriole
#

@frozen latch vercel Cross-site POST form submissions are forbidden

frozen latchBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

This error is caused by CSRF protection, which is enabled by default in Astro v5. Astro automatically checks that the origin header matches the URL for cross-site POST form submissions on on-demand rendered pages. [CSRF protection]

Fix

You can disable this check in your astro.config.mjs:

import { defineConfig } from 'astro/config';
import vercel from '@astrojs/vercel';
import tailwindcss from '@tailwindcss/vite';

export default defineConfig({
  output: "server",
  security: {
    checkOrigin: false
  },
  adapter: vercel({
    maxDuration: 60,
  }),
  vite: {
    plugins: [tailwindcss()]
  }
});

[security config]

What's happening

Astro v5 defaults security.checkOrigin to true. It checks the origin header on POST, PATCH, DELETE, and PUT requests with content types like application/x-www-form-urlencoded or multipart/form-data. If the origin doesn't match the request URL (which can happen on Vercel due to how requests are routed), Astro returns a 403 Forbidden and blocks the form submission. [checkOrigin]

Setting checkOrigin: false disables this behavior and should resolve the "Cross-site POST form submissions are forbidden" error.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: