Repository navigation
fix: The portal login page is not displaying the custom name. - #7885
Conversation
| export type PortalAuthProfile = AuthProfile<PortalAuthProfileMeta> | ||
|
|
||
| export interface ChatLoginRequest { | ||
| username: string |
There was a problem hiding this comment.
Review of the diff
-
Type-safety break introduced (potential bug in callers).
ChangingPortalAuthProfilefromAuthProfile(default generic) toAuthProfile<PortalAuthProfileMeta>narrows the type. Any code that previously constructed aPortalAuthProfilewith the old meta shape (or relied on the default generic) will now fail to compile or pass an incompatible object. Verify all usages:- Usages of
AuthProfilewithout generics — what is the default? If it'sAuthProfile<unknown>orAuthProfile<any>, existing assignments may silently continue working but lose safety. - Any serialized/deserialized portal configs in tests, fixtures, or persisted data that lack
portal_name.
- Usages of
-
Consistency with
ApplicationAuthProfile. The pattern matches — good. But confirm:- Is there an analogous runtime validator / schema (e.g., zod, JSON schema) that must also gain
portal_name? Type-only changes won't enforce anything at runtime. - Backend API contract: does the portal auth profile endpoint actually return
portal_name? If not, the declared type lies.
- Is there an analogous runtime validator / schema (e.g., zod, JSON schema) that must also gain
-
Required vs optional field.
portal_name: stringis required. If older putaways/records may omit it (backwards compatibility), considerportal_name?: stringor a migration path. Same question forapplication_name— if it's already required, fine, but be explicit about why. -
Naming/generic default. Check
AuthProfile's definition: if its generic has a default like= unknown, thenAuthProfilewrites remain valid and the change is safe-ish; if the default is something else (e.g.,Record<string, any>), document the intent. Consider making the generic constraint explicit (AuthProfile<T extends ...>). -
Optimization (minor).
- Consider defining a shared base for name-bearing metas:
Not necessary, but avoids drift if more fields converge later.
interface NamedPortalMeta { portal_name: string }
- No performance concerns — compile-time only.
- Consider defining a shared base for name-bearing metas:
-
Diff hygiene. The hunk header says
@@ -20,11 +20,15 @@but the visible context is small; ensure surrounding declarations (e.g., other*AuthProfileMetainterfaces) are consistent in JSDoc style (English comment added/** 单应用… */exists; the newPortalAuthProfileMetalacks a doc comment). Add one for consistency. -
No tests visible. Add/adjust a type/unit test asserting a valid
PortalAuthProfilerequiresportal_nameand that downstream consumers accept it.
Verdict: Structurally correct and consistent with the application counterpart, but semantically breaking — grep all PortalAuthProfile usages, check runtime schemas and backend contracts, and decide whether portal_name should be optional for backward compatibility before merging.
| } | ||
| return (auth.authProfile?.meta as ApplicationAuthProfileMeta | undefined)?.application_name || '登录' | ||
| }) | ||
|
|
There was a problem hiding this comment.
Here's the review of the provided diff:
Issues / Potential Problems
-
Unsafe type cast (
as): The code castsauth.authProfile?.metatoPortalAuthProfileMeta | undefinedandApplicationAuthProfileMeta | undefined. Sincemetais likely typed as a union or generic object, this cast can hide real type errors. Prefer a type guard or discriminated union narrowing (e.g., based on atypefield) instead ofas. -
Leftover debug statement:
console.log(auth)is still present. This should be removed before merging (or gated behind a dev flag). -
||vs??for fallback: Using|| '门户登录'will also fall back whenportal_nameis an empty string''. If an emptyportal_nameis invalid data anyway, this is fine; otherwise use??to only fall back onnull/undefined. Decide intentionally which behavior you want. -
Reduced testability/typing: The inline cast inside
computedmakes the computed less self-documenting. Consider extracting a helper likegetPortalName(meta)with proper typing and unit tests.
Optimization Suggestions
- Cache meta lookup: Minor, but the computed re-runs whenever
authidentity changes; sinceauth.isPortalandauth.authProfile.metaare related, consider using separate computeds (isPortal,meta) for clarity and better reactivity granularity — not required but cleaner. - Import ordering / formatting: The import line is long; if ESLint
max-lenapplies, movingPortalAuthProfileMetato a separateimport typeblock may help readability. - Consistency: Ensure Chinese default strings ('门户登录', '登录') align with i18n strategy if the project uses localization — hardcoding titles reduces maintainability.
Minor correctness note
The logic itself is sound: portal → portal_name fallback, otherwise application_name fallback. No functional bug introduced by the change, assuming meta really holds those shapes per mode.
fix: The portal login page is not displaying the custom name.