e2e: remove auth bypass; use real Clerk sign-in in Cypress

This commit is contained in:
Kunal
2026-02-07 16:57:41 +00:00
parent 7d407b073e
commit ac1c90c742
4 changed files with 70 additions and 74 deletions

View File

@@ -302,7 +302,7 @@ export default function ActivityPage() {
forceRedirectUrl="/activity"
signUpForceRedirectUrl="/activity"
>
<Button className="mt-4">Sign in</Button>
<Button className="mt-4" data-testid="activity-signin">Sign in</Button>
</SignInButton>
</div>
</div>

View File

@@ -19,29 +19,20 @@ import type { ComponentProps } from "react";
import { isLikelyValidClerkPublishableKey } from "@/auth/clerkKey";
function isE2EAuthBypassEnabled(): boolean {
// Used only for Cypress E2E to keep tests secretless and deterministic.
// When enabled, we treat the user as signed in and skip Clerk entirely.
return process.env.NEXT_PUBLIC_E2E_AUTH_BYPASS === "1";
}
export function isClerkEnabled(): boolean {
// IMPORTANT: keep this in sync with AuthProvider; otherwise components like
// <SignedOut/> may render without a <ClerkProvider/> and crash during prerender.
if (isE2EAuthBypassEnabled()) return false;
return isLikelyValidClerkPublishableKey(
process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY,
);
}
export function SignedIn(props: { children: ReactNode }) {
if (isE2EAuthBypassEnabled()) return <>{props.children}</>;
if (!isClerkEnabled()) return null;
return <ClerkSignedIn>{props.children}</ClerkSignedIn>;
}
export function SignedOut(props: { children: ReactNode }) {
if (isE2EAuthBypassEnabled()) return null;
if (!isClerkEnabled()) return <>{props.children}</>;
return <ClerkSignedOut>{props.children}</ClerkSignedOut>;
}
@@ -67,15 +58,6 @@ export function useUser() {
}
export function useAuth() {
if (isE2EAuthBypassEnabled()) {
return {
isLoaded: true,
isSignedIn: true,
userId: "e2e-user",
sessionId: "e2e-session",
getToken: async () => "e2e-token",
} as const;
}
if (!isClerkEnabled()) {
return {
isLoaded: true,