Self-host compose stack and production stability fixes

这个提交包含在:
cryptocommuniums-afk
2026-03-14 22:25:19 +08:00
父节点 f5ad0449a8
当前提交 8df0f91db7
修改 19 个文件,包含 329 行新增54 行删除

29
client/src/const.test.ts 普通文件
查看文件

@@ -0,0 +1,29 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { getLoginUrl } from "./const";
describe("getLoginUrl", () => {
afterEach(() => {
vi.unstubAllEnvs();
});
it("falls back to the in-app login route when oauth portal is unset", () => {
vi.stubEnv("VITE_OAUTH_PORTAL_URL", "");
expect(getLoginUrl()).toBe("/login");
});
it("builds the external oauth login url when portal is configured", () => {
vi.stubEnv("VITE_OAUTH_PORTAL_URL", "https://oauth.example.com");
vi.stubEnv("VITE_APP_ID", "tennis-training-hub");
const url = new URL(getLoginUrl());
expect(url.origin).toBe("https://oauth.example.com");
expect(url.pathname).toBe("/app-auth");
expect(url.searchParams.get("appId")).toBe("tennis-training-hub");
expect(url.searchParams.get("redirectUri")).toBe(
`${window.location.origin}/api/oauth/callback`
);
expect(url.searchParams.get("type")).toBe("signIn");
});
});

查看文件

@@ -2,8 +2,13 @@ export { COOKIE_NAME, ONE_YEAR_MS } from "@shared/const";
// Generate login URL at runtime so redirect URI reflects the current origin.
export const getLoginUrl = () => {
const oauthPortalUrl = import.meta.env.VITE_OAUTH_PORTAL_URL;
const oauthPortalUrl = import.meta.env.VITE_OAUTH_PORTAL_URL?.trim();
const appId = import.meta.env.VITE_APP_ID;
if (!oauthPortalUrl) {
return "/login";
}
const redirectUri = `${window.location.origin}/api/oauth/callback`;
const state = btoa(redirectUri);