@autional/shared 0.1.0-rc.44 → 0.1.0-rc.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autional/shared",
3
- "version": "0.1.0-rc.44",
3
+ "version": "0.1.0-rc.45",
4
4
  "description": "Autional shared layer — API client, auth, types, hooks, utils",
5
5
  "license": "AGPL-3.0",
6
6
  "main": "./src/index.ts",
package/src/auth/roles.ts CHANGED
@@ -92,14 +92,18 @@ export function isAuthLoginSurface(): boolean {
92
92
  return segs.length === 2 && segs[1] === 'login'; // `/<slug>/login`
93
93
  }
94
94
 
95
- export function buildLoginUrl(returnUrl?: string, fromRequireAuth?: boolean): string {
95
+ export function buildLoginUrl(
96
+ returnUrl?: string,
97
+ fromRequireAuth?: boolean,
98
+ tenantSlug?: string | null,
99
+ ): string {
96
100
  const base = getPortalUrl('auth');
97
101
  if (!base) return '/';
98
102
 
99
- // 保留租户 slug:如果 returnUrl 落在 auth 域且首段是租户 slug,
100
- // 跳转到 {base}/{slug}/login 而不是根路径(根路径是租户选择页)
101
- let loginBase = base;
102
- if (returnUrl) {
103
+ // 租户上下文优先级:显式 tenantSlug > returnUrl 首段推导 > auth 根(租户选择页)。
104
+ // 显式参数用于「站点在根路径(无 slug)但已知当前/最近租户」的场景。
105
+ let loginBase = tenantSlug ? `${base}/${encodeURIComponent(tenantSlug)}/login` : base;
106
+ if (!tenantSlug && returnUrl) {
103
107
  try {
104
108
  const clean = new URL(returnUrl, typeof window !== 'undefined' ? window.location.origin : '');
105
109
  const baseOrigin = new URL(base).origin;
@@ -48,11 +48,17 @@ export function applyBrandColors(color: string, darkOverride?: string): void {
48
48
  setColorVar(root, '--color-on-brand-dark', pickOnColor(dark));
49
49
  }
50
50
 
51
+ export interface UseBrandingOptions {
52
+ /** 是否注入租户自定义 CSS;默认 true。认证器/验证码页应传 false。 */
53
+ applyCustomCss?: boolean;
54
+ }
55
+
51
56
  /**
52
57
  * 把当前租户品牌落到 DOM(CSS 变量 / favicon / customCss)。
53
58
  * 需与 `<BrandingInitializer/>` 同时挂载:前者负责写 store,这里负责呈现。
54
59
  */
55
- export function useBranding(): void {
60
+ export function useBranding(options?: UseBrandingOptions): void {
61
+ const applyCustomCss = options?.applyCustomCss ?? true;
56
62
  const branding = useTenantBrandingStore((s) => s.branding);
57
63
  const slug = useTenantSlugFromUrl();
58
64
  const styleRef = useRef<HTMLStyleElement | null>(null);
@@ -84,18 +90,26 @@ export function useBranding(): void {
84
90
  favicon.href = branding.faviconUrl;
85
91
  }
86
92
 
87
- if (branding.customCss) {
93
+ if (branding.customCss && applyCustomCss) {
88
94
  if (!styleRef.current) {
89
95
  styleRef.current = document.createElement('style');
90
96
  styleRef.current.setAttribute('data-tenant-css', '');
91
97
  document.head.appendChild(styleRef.current);
92
98
  }
93
99
  styleRef.current.textContent = branding.customCss;
100
+ } else if (styleRef.current) {
101
+ styleRef.current.textContent = '';
102
+ styleRef.current.remove();
103
+ styleRef.current = null;
94
104
  }
95
105
 
96
106
  return () => {
97
107
  applyBrandColors('');
98
- if (styleRef.current) styleRef.current.textContent = '';
108
+ if (styleRef.current) {
109
+ styleRef.current.textContent = '';
110
+ styleRef.current.remove();
111
+ styleRef.current = null;
112
+ }
99
113
  };
100
- }, [branding]);
114
+ }, [branding, applyCustomCss]);
101
115
  }