RockteMQ-AI commented on code in PR #2876:
URL:
https://github.com/apache/rocketmq-dashboard/pull/2876#discussion_r3899685953
##########
web/src/pages/login/index.tsx:
##########
@@ -50,8 +50,12 @@ const LoginPage = () => {
const onFinish = async (values: LoginFormValues) => {
setLoading(true);
try {
- const data = await loginApi(values.username, values.password);
- authLogin(data.user.username, data.user.userId, data.user.admin);
+ const data = await loginApi(values.username.trim(), values.password);
Review Comment:
**[Info]** Good defensive improvement — using optional chaining on
`data?.user` and then validating `user?.username` before accessing properties
prevents crashes on malformed API responses. Combined with the `whitespace:
true` form rule, this makes the login flow significantly more robust.
##########
web/src/pages/login/index.tsx:
##########
@@ -50,8 +50,12 @@ const LoginPage = () => {
const onFinish = async (values: LoginFormValues) => {
setLoading(true);
try {
- const data = await loginApi(values.username, values.password);
- authLogin(data.user.username, data.user.userId, data.user.admin);
+ const data = await loginApi(values.username.trim(), values.password);
+ const user = data?.user;
+ if (!user?.username) {
+ throw new Error(t('login.failed'));
Review Comment:
**[Info]** Minor note: `throw new Error(t('login.failed'))` translates the
message at throw time. This works correctly since the catch block displays
`err.message` directly, but if the error handling ever changes (e.g., logging
the raw error or re-translating), the already-localized string could cause
issues. Consider using a stable error key and mapping it in the catch block —
though this is a minor style preference, not a blocker.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]