SolidJSS
SolidJS13mo ago
3 replies
fpalla

redirecting from API route

Hey all! I'm trying to redirect to a page (/app) from a API get route after exchanging the token with supabase.
For some reason it works when using locally and it behaves correctly, but it doesn't wotk when deployed (on Vercel).

Am I doing something really wrong / missing something?
I've even tried to manually return a response instead of using the redirect but the behaviour is the same.

The whole route code looks like this

`
import { redirect } from "@solidjs/router";
import type { APIEvent } from "@solidjs/start/server";
import { createClient } from "~/services/supabase.server";


export async function GET(event: APIEvent) {
  const { request } = event;
  const requestUrl = new URL(request.url);
  const code = requestUrl.searchParams.get("code");

  if (!code) {
    console.log("NO CODE");
    return redirect("/app");
  }

  const supabase = createClient();
  const { error } = await supabase.auth.exchangeCodeForSession(code);

  if (error) {
    console.log("LOGIN ERROR", error);
  }

  const response = redirect("/app");

  console.log(response);
  return response;
}


Appreciate any pointers/ suggestion!
Was this page helpful?