MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / sendCode

Function sendCode

web/src/components/auth/OAuth2Callback.js:17–51  ·  view source on GitHub ↗
(code, state, retry = 0)

Source from the content-addressed store, hash-verified

15 const MAX_RETRIES = 3;
16
17 const sendCode = async (code, state, retry = 0) => {
18 try {
19 const { data: resData } = await API.get(
20 `/api/oauth/${props.type}?code=${code}&state=${state}`,
21 );
22
23 const { success, message, data } = resData;
24
25 if (!success) {
26 throw new Error(message || 'OAuth2 callback error');
27 }
28
29 if (message === 'bind') {
30 showSuccess(t('绑定成功!'));
31 navigate('/console/personal');
32 } else {
33 userDispatch({ type: 'login', payload: data });
34 localStorage.setItem('user', JSON.stringify(data));
35 setUserData(data);
36 updateAPI();
37 showSuccess(t('登录成功!'));
38 navigate('/console/token');
39 }
40 } catch (error) {
41 if (retry < MAX_RETRIES) {
42 // 递增的退避等待
43 await new Promise((resolve) => setTimeout(resolve, (retry + 1) * 2000));
44 return sendCode(code, state, retry + 1);
45 }
46
47 // 重试次数耗尽,提示错误并返回设置页面
48 showError(error.message || t('授权失败'));
49 navigate('/console/personal');
50 }
51 };
52
53 useEffect(() => {
54 const code = searchParams.get('code');

Callers 1

OAuth2CallbackFunction · 0.85

Calls 5

showSuccessFunction · 0.90
setUserDataFunction · 0.90
updateAPIFunction · 0.90
showErrorFunction · 0.90
tFunction · 0.50

Tested by

no test coverage detected