import type { APIEvent } from "@solidjs/start/server";
import { appRouter } from "~/server/api/root";
import { createTRPCContext } from "~/server/api/utils";
export async function GET(event: APIEvent) {
const url = new URL(event.request.url);
const email = url.searchParams.get("email");
const token = url.searchParams.get("token");
// Missing required parameters
if (!email || !token) {
return new Response(
`
Email Verification Error
❌ Verification Failed
Invalid verification link. Please check your email and try again.
Return to Login
`,
{
status: 400,
headers: { "Content-Type": "text/html" },
}
);
}
try {
// Create tRPC caller to invoke the emailVerification procedure
const ctx = await createTRPCContext(event);
const caller = appRouter.createCaller(ctx);
// Call the email verification handler
const result = await caller.auth.emailVerification({
email,
token,
});
if (result.success) {
// Show success page
return new Response(
`
Email Verified
✓
Email Verified!
${result.message || "Your email has been successfully verified."}
Continue to Login
`,
{
status: 200,
headers: { "Content-Type": "text/html" },
}
);
} else {
throw new Error("Verification failed");
}
} catch (error) {
console.error("Email verification callback error:", error);
// Check if it's a token expiration error
const errorMessage = error instanceof Error ? error.message : "server_error";
const isTokenError = errorMessage.includes("expired") || errorMessage.includes("invalid");
return new Response(
`
Email Verification Error
❌ Verification Failed
${isTokenError ? "This verification link has expired. Please request a new verification email." : "An error occurred during verification. Please try again."}
Return to Login
`,
{
status: 400,
headers: { "Content-Type": "text/html" },
}
);
}
}