Redirect terminal non-members to checkout after login

This commit is contained in:
2569718930@qq.com
2026-06-14 02:49:18 +08:00
parent 285191a8be
commit c4cf69c67f
3 changed files with 125 additions and 7 deletions
@@ -0,0 +1,38 @@
import fs from "node:fs";
import path from "node:path";
function assert(condition: unknown, message: string) {
if (!condition) throw new Error(message);
}
export function runTests() {
const projectRoot = process.cwd();
const loginClientSource = fs.readFileSync(
path.join(projectRoot, "components", "auth", "LoginClient.tsx"),
"utf8",
);
const authCallbackSource = fs.readFileSync(
path.join(projectRoot, "app", "auth", "callback", "route.ts"),
"utf8",
);
assert(
loginClientSource.includes("TERMINAL_CHECKOUT_PATH") &&
loginClientSource.includes('"/account?checkout=1"') &&
loginClientSource.includes("resolvePostLoginRedirect") &&
loginClientSource.includes("subscription_active === false") &&
loginClientSource.includes("router.replace(redirectPath)") &&
!loginClientSource.includes("router.replace(nextPath);\n return;"),
"email/password terminal login must send non-members to the checkout account page instead of blindly returning to /terminal",
);
assert(
authCallbackSource.includes("resolvePostAuthRedirect") &&
authCallbackSource.includes("TERMINAL_CHECKOUT_PATH") &&
authCallbackSource.includes('"/account?checkout=1"') &&
authCallbackSource.includes("subscription_active === false") &&
authCallbackSource.includes("NextResponse.redirect(redirectUrl)") &&
authCallbackSource.includes("await resolvePostAuthRedirect"),
"OAuth terminal callback must send non-members to the checkout account page instead of blindly returning to /terminal",
);
}