feat: aggressive logging

This commit is contained in:
Nicholas Tindle
2025-10-18 02:16:46 -05:00
parent 605a198c09
commit d4a7ce3846
2 changed files with 119 additions and 10 deletions

View File

@@ -48,9 +48,12 @@ export function useSignupPage() {
}, [user]);
async function handleProviderSignup(provider: LoginProvider) {
console.log("=== CLIENT OAUTH SIGNUP START ===");
console.log("Provider:", provider);
setIsGoogleLoading(true);
if (isCloudEnv && !turnstile.verified && !isVercelPreview) {
console.log("OAuth: CAPTCHA not verified - showing toast");
toast({
title: "Please complete the CAPTCHA challenge.",
variant: "default",
@@ -59,24 +62,36 @@ export function useSignupPage() {
resetCaptcha();
return;
}
try {
console.log("Making OAuth provider request...");
const response = await fetch("/api/auth/provider", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ provider }),
});
console.log("OAuth API Response:", {
status: response.status,
statusText: response.statusText,
ok: response.ok,
});
if (!response.ok) {
const { error } = await response.json();
console.log("OAuth failed with error:", error);
setIsGoogleLoading(false);
resetCaptcha();
// Check for waitlist error
if (error === "not_allowed") {
console.log(">>> OAUTH NOT ALLOWED ERROR DETECTED <<<");
console.log("Showing not allowed modal");
setShowNotAllowedModal(true);
return;
}
console.log("Other OAuth error - showing toast:", error);
toast({
title: error || "Failed to start OAuth flow",
variant: "destructive",
@@ -85,9 +100,15 @@ export function useSignupPage() {
}
const { url } = await response.json();
if (url) window.location.href = url as string;
console.log("OAuth redirect URL received:", url ? "✓" : "✗");
if (url) {
console.log("=== CLIENT OAUTH END - REDIRECTING ===");
window.location.href = url as string;
}
setFeedback(null);
} catch (error) {
console.error("=== CLIENT OAUTH EXCEPTION ===");
console.error("Caught error:", error);
setIsGoogleLoading(false);
resetCaptcha();
toast({
@@ -99,9 +120,19 @@ export function useSignupPage() {
}
async function handleSignup(data: z.infer<typeof signupFormSchema>) {
console.log("=== CLIENT SIGNUP START ===");
console.log("Attempting signup for email:", data.email);
console.log("Environment:", {
isCloudEnv,
isVercelPreview,
turnstileVerified: turnstile.verified,
hasTurnstileToken: !!turnstile.token,
});
setIsLoading(true);
if (isCloudEnv && !turnstile.verified && !isVercelPreview) {
console.log("CAPTCHA not verified - showing toast");
toast({
title: "Please complete the CAPTCHA challenge.",
variant: "default",
@@ -112,6 +143,7 @@ export function useSignupPage() {
}
if (data.email.includes("@agpt.co")) {
console.log("AutoGPT email detected - redirecting to Google SSO");
toast({
title:
"Please use Google SSO to create an account using an AutoGPT email.",
@@ -124,31 +156,53 @@ export function useSignupPage() {
}
try {
console.log("Making signup API request...");
const requestBody = {
email: data.email,
password: data.password,
confirmPassword: data.confirmPassword,
agreeToTerms: data.agreeToTerms,
turnstileToken: turnstile.token,
};
console.log("Request body:", {
...requestBody,
password: "[REDACTED]",
confirmPassword: "[REDACTED]",
});
const response = await fetch("/api/auth/signup", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
email: data.email,
password: data.password,
confirmPassword: data.confirmPassword,
agreeToTerms: data.agreeToTerms,
turnstileToken: turnstile.token,
}),
body: JSON.stringify(requestBody),
});
console.log("API Response received:", {
status: response.status,
statusText: response.statusText,
ok: response.ok,
});
const result = await response.json();
console.log("Response body:", result);
setIsLoading(false);
if (!response.ok) {
console.log("Signup failed with error:", result?.error);
if (result?.error === "user_already_exists") {
console.log("User already exists error detected");
setFeedback("User with this email already exists");
turnstile.reset();
return;
}
if (result?.error === "not_allowed") {
console.log(">>> NOT ALLOWED ERROR DETECTED <<<");
console.log("Showing not allowed modal");
setShowNotAllowedModal(true);
return;
}
console.log("Other signup error - showing toast:", result?.error);
toast({
title: result?.error || "Signup failed",
variant: "destructive",
@@ -158,10 +212,15 @@ export function useSignupPage() {
return;
}
console.log("Signup successful!");
setFeedback(null);
const next = (result?.next as string) || "/";
console.log("Redirecting to:", next);
console.log("=== CLIENT SIGNUP END SUCCESS ===");
router.push(next);
} catch (error) {
console.error("=== CLIENT SIGNUP EXCEPTION ===");
console.error("Caught error:", error);
setIsLoading(false);
toast({
title:

View File

@@ -7,8 +7,18 @@ import { shouldShowOnboarding } from "../../helpers";
import { isWaitlistError, logWaitlistError } from "../utils";
export async function POST(request: Request) {
console.log("=== SIGNUP ROUTE START ===");
console.log("Timestamp:", new Date().toISOString());
try {
const body = await request.json();
console.log("Request body received:", {
hasEmail: !!body?.email,
hasPassword: !!body?.password,
hasConfirmPassword: !!body?.confirmPassword,
agreeToTerms: body?.agreeToTerms,
hasTurnstileToken: !!body?.turnstileToken,
});
const parsed = signupFormSchema.safeParse({
email: body?.email,
@@ -18,61 +28,101 @@ export async function POST(request: Request) {
});
if (!parsed.success) {
console.error("Schema validation failed:", parsed.error.errors);
return NextResponse.json(
{ error: "Invalid signup payload" },
{ status: 400 },
);
}
console.log("Schema validation passed for email:", parsed.data.email);
const turnstileToken: string | undefined = body?.turnstileToken;
console.log("Starting CAPTCHA verification...");
const captchaOk = await verifyTurnstileToken(
turnstileToken ?? "",
"signup",
);
if (!captchaOk) {
console.error("CAPTCHA verification failed");
return NextResponse.json(
{ error: "CAPTCHA verification failed. Please try again." },
{ status: 400 },
);
}
console.log("CAPTCHA verification successful");
console.log("Getting Supabase client...");
const supabase = await getServerSupabase();
if (!supabase) {
console.error("Failed to get Supabase client");
return NextResponse.json(
{ error: "Authentication service unavailable" },
{ status: 500 },
);
}
console.log("Supabase client obtained successfully");
console.log("Attempting signup for email:", parsed.data.email);
const { data, error } = await supabase.auth.signUp(parsed.data);
console.log("Supabase signup response:", {
hasData: !!data,
hasError: !!error,
hasSession: !!data?.session,
hasUser: !!data?.user,
});
if (error) {
console.error("=== SIGNUP ERROR DETAILS ===");
console.error("Error object:", {
message: error.message,
code: (error as any).code,
status: (error as any).status,
name: error.name,
stack: error.stack?.split("\n")[0], // First line of stack
});
// Check for waitlist/allowlist error
if (isWaitlistError(error)) {
const isWaitlist = isWaitlistError(error);
console.log("Is waitlist error?", isWaitlist);
if (isWaitlist) {
console.log(">>> WAITLIST ERROR DETECTED <<<");
console.log("Error message before sanitization:", error.message);
logWaitlistError("Signup", error.message);
return NextResponse.json({ error: "not_allowed" }, { status: 403 });
}
if ((error as any).code === "user_already_exists") {
console.log("User already exists error");
return NextResponse.json(
{ error: "user_already_exists" },
{ status: 409 },
);
}
console.log("Signup error:", error);
console.log("Other signup error:", error.message);
return NextResponse.json({ error: error.message }, { status: 400 });
}
if (data.session) {
console.log("Setting session for new user");
await supabase.auth.setSession(data.session);
} else {
console.log("No session returned - user may need email confirmation");
}
const isOnboardingEnabled = await shouldShowOnboarding();
const next = isOnboardingEnabled ? "/onboarding" : "/";
console.log("Signup successful. Redirecting to:", next);
console.log("=== SIGNUP ROUTE END SUCCESS ===");
return NextResponse.json({ success: true, next });
} catch (err) {
console.error("=== UNEXPECTED ERROR IN SIGNUP ===");
console.error("Error:", err);
Sentry.captureException(err);
return NextResponse.json(
{ error: "Failed to sign up. Please try again." },