feat: switch TRPC router to edge
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { type EmailOtpType } from "@supabase/supabase-js";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import createClient from "~/utils/supabase/api";
|
||||
import { createNextClient } from "~/utils/supabase/api";
|
||||
|
||||
function stringOrFirstString(item: string | string[] | undefined) {
|
||||
return Array.isArray(item) ? item[0] : item;
|
||||
@@ -23,7 +23,7 @@ export default async function handler(
|
||||
let next = "/error";
|
||||
|
||||
if (token_hash && type) {
|
||||
const supabase = createClient(req, res);
|
||||
const supabase = createNextClient(req, res);
|
||||
const { error } = await supabase.auth.verifyOtp({
|
||||
type: type as EmailOtpType,
|
||||
token_hash,
|
||||
@@ -37,3 +37,7 @@ export default async function handler(
|
||||
|
||||
res.redirect(next);
|
||||
}
|
||||
|
||||
// export const runtime = "edge";
|
||||
// export const preferredRegion = "lhr1";
|
||||
// export const dynamic = "force-dynamic";
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
import { type NextApiRequest, type NextApiResponse } from "next";
|
||||
import { createNextApiHandler } from "@trpc/server/adapters/next";
|
||||
import { type NextRequest } from "next/server";
|
||||
import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
|
||||
|
||||
import { env } from "~/env.mjs";
|
||||
import { appRouter } from "~/server/api/root";
|
||||
import { createTRPCContext } from "~/server/api/trpc";
|
||||
|
||||
const nextApiHandler = createNextApiHandler({
|
||||
router: appRouter,
|
||||
createContext: createTRPCContext,
|
||||
onError:
|
||||
env.NODE_ENV === "development"
|
||||
? ({ path, error }) => {
|
||||
console.error(
|
||||
`❌ tRPC failed on ${path ?? "<no-path>"}: ${error.message}`,
|
||||
);
|
||||
}
|
||||
: undefined,
|
||||
});
|
||||
|
||||
export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
return nextApiHandler(req, res);
|
||||
export default async function handler(req: NextRequest) {
|
||||
return fetchRequestHandler({
|
||||
endpoint: "/api/trpc",
|
||||
router: appRouter,
|
||||
req,
|
||||
createContext: createTRPCContext,
|
||||
onError:
|
||||
env.NODE_ENV === "development"
|
||||
? ({ path, error }) => {
|
||||
console.error(
|
||||
`❌ tRPC failed on ${path ?? "<no-path>"}: ${error.message}`,
|
||||
);
|
||||
}
|
||||
: undefined,
|
||||
});
|
||||
}
|
||||
|
||||
// export const runtime = "edge";
|
||||
// export const preferredRegion = 'lhr1';
|
||||
// export const dynamic = 'force-dynamic'
|
||||
export const runtime = "edge";
|
||||
export const preferredRegion = "lhr1";
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
Reference in New Issue
Block a user