's'
This commit is contained in:
@@ -38,10 +38,14 @@ type RecoveryResult = {
|
||||
const inflightEmailChecks = new Map<string, Promise<PayjsVipEmailResult | null>>();
|
||||
|
||||
const PAYJS_CHECK_BY_EMAIL_TIMEOUT =
|
||||
Number(process.env.PAYJSAPI_CHECK_BY_EMAIL_TIMEOUT) || 20000;
|
||||
Number(process.env.PAYJSAPI_CHECK_BY_EMAIL_TIMEOUT) || 20_000;
|
||||
const PAYJS_CHECK_BY_EMAIL_RETRIES =
|
||||
Math.max(0, Number(process.env.PAYJSAPI_CHECK_BY_EMAIL_RETRIES) || 1);
|
||||
|
||||
const PB_USER_LOGIN_TIMEOUT_MS =
|
||||
Number(process.env.POCKETBASE_USER_LOGIN_TIMEOUT_MS) ||
|
||||
(process.env.NODE_ENV === "development" ? 30_000 : 15_000);
|
||||
|
||||
function resolvePayApiUrl(request: NextRequest): string {
|
||||
const payConfig = getPaymentConfig();
|
||||
const hostHeader = request.headers.get("host") || request.headers.get("x-forwarded-host");
|
||||
@@ -154,6 +158,7 @@ async function loginPocketBaseUser(
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ identity: email, password }),
|
||||
cache: "no-store",
|
||||
signal: AbortSignal.timeout(PB_USER_LOGIN_TIMEOUT_MS),
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
@@ -301,6 +306,11 @@ export async function POST(request: NextRequest) {
|
||||
}
|
||||
|
||||
try {
|
||||
const adminTokenPromise = getAdminToken().catch((error) => {
|
||||
console.error("[check-by-email] getAdminToken failed:", error);
|
||||
return null;
|
||||
});
|
||||
|
||||
let authData: { token: string; record: PBAuthRecord } | null = null;
|
||||
let loginError: string | null = null;
|
||||
try {
|
||||
@@ -339,10 +349,7 @@ export async function POST(request: NextRequest) {
|
||||
);
|
||||
}
|
||||
|
||||
const adminToken = await getAdminToken().catch((error) => {
|
||||
console.error("[check-by-email] getAdminToken failed:", error);
|
||||
return null;
|
||||
});
|
||||
const adminToken = await adminTokenPromise;
|
||||
if (!adminToken) {
|
||||
// 管理员 token 获取失败时,降级到 payjsapi 结果,避免直接 500
|
||||
if (!payjsResult) {
|
||||
|
||||
Reference in New Issue
Block a user