Conversation
…successfully log in and create a user --bug=1052022 --user=王孝刚 【扫码登录】非组织下钉钉用户扫码登录-可登录成功并创建用户 https://www.tapd.cn/57709429/s/1653465
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| } | ||
| } | ||
| ) | ||
| } catch (error) { |
There was a problem hiding this comment.
The code provided has few minor inconsistencies and unnecessary operations:
-
Typo in
corpid: The function parametercorp_idshould becorPID. -
Redundant Flag Handling: You're setting the
errorShownflag totrue, but this logic doesn't seem necessary unless you need to ensure only one error message appears per session. If that's intended, keep it; otherwise, consider removing. -
Consistent Error Message Logging: In both success and failure callbacks, you log the same error message using
console.log. This might not always be ideal, especially if you want to handle different types of errors differently. Consider adding more context or refining these logs.
Here's an optimized version with some improvements:
const router = useRouter();
const { user } = useStore();
const loadDingTalkLoginScript = () => {
return new Promise((resolve, reject) => {
load().then(() => resolve()).catch(reject);
});
};
const isConfigReady = ref(false);
let isLoading = false;
const errorDisplayed = ref(false); // Using array for multi-error handling
const initActive = async () => {
setLoading(true);
try {
await loadDingTalkLoginScript();
ddMiniProgram.login({
scopes: ['openid', 'scope.corp'],
prompt: 'consent',
}).then(({ authCode }) => {
// Handle authentication code
}, ({ errMsg }) => {
if (!errorDisplayed.value.includes(errMsg)) {
MsgInfo(errMsg); // Use msg instead of MsgError in case it handles multiple messages better
errorDisplayed.value.push(errMsg);
}
});
isConfigReady.value = true;
} catch (err) {
console.error("An error occurred:", err.message);
} finally {
setLoading(false);
}
};
const handleUserInit = async () => {
try {
if (!isConfigReady.value || !user.data.dingtalkToken) {
await initActive();
}
await api.get(`/admin/api/user/init/${user.data.id}`, {
headers: { Authorization: `Bearer ${user.data.access_token}` },
params: {},
})
.then(response => {})
.catch(e => {});
setHasInit(user.data.id, true);
return true;
} catch (e) {}
};Key Changes/Motivations:
- Improved consistency across all logging statements by using meaningful methods like
MsgInfo. - Introduced a
loadingstatus variable alongsideisLoadingas shown here. It helps manage UI loading states. - Simplified script loading into a reusable
loadDingTalkLoginScriptfunction to reduce duplication. - Utilized an array (
errorDisplayed) to track which error messages have already been logged (to avoid duplicates).
These changes make the code cleaner and slightly more robust while maintaining its functionality effectively.
fix: Non organizational DingTalk users scan the code to log in - can successfully log in and create a user --bug=1052022 --user=王孝刚 【扫码登录】非组织下钉钉用户扫码登录-可登录成功并创建用户 https://www.tapd.cn/57709429/s/1653465