@shun-js/webcc-server 0.6.9 → 0.7.0

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": "@shun-js/webcc-server",
3
- "version": "0.6.9",
3
+ "version": "0.7.0",
4
4
  "description": "webcc.dev server",
5
5
  "keywords": [
6
6
  "web claude code"
@@ -32,5 +32,5 @@
32
32
  "access": "public",
33
33
  "registry": "https://registry.npmjs.org/"
34
34
  },
35
- "gitHead": "2e16481e703d73845eac724b043e641a56346041"
35
+ "gitHead": "7b00c44a58b64b17d54327820cf1d44fa00464dd"
36
36
  }
@@ -69,6 +69,11 @@ exports.githubCallback = async (req, res) => {
69
69
  }
70
70
 
71
71
  // userinfo
72
- await getGithubUserinfo(queryCode);
72
+ const githubUserinfo = await getGithubUserinfo(req, queryCode);
73
+ if (!githubUserinfo) {
74
+ req.logger.error(methodName, 'githubUserinfo is null');
75
+ res.redirect(fallbackUrl);
76
+ return;
77
+ }
73
78
  res.send('1');
74
79
  };
@@ -24,9 +24,12 @@ exports.getGitHubAuthUrl = () => {
24
24
 
25
25
  /**
26
26
  * getGithubUserinfo
27
+ * @param {*} req
27
28
  * @param {*} code
28
29
  */
29
- exports.getGithubUserinfo = async (code) => {
30
+ exports.getGithubUserinfo = async (req, code) => {
31
+ const methodName = 'getGithubUserinfo';
32
+
30
33
  try {
31
34
  // get token
32
35
  const tokenUrl = global.QZ_CONFIG.github.tokenUrl;
@@ -41,10 +44,104 @@ exports.getGithubUserinfo = async (code) => {
41
44
  Accept: 'application/json',
42
45
  },
43
46
  };
44
- console.log(tokenConfig);
45
47
  const tokenResponse = await get(tokenUrl, tokenConfig);
46
- console.log(tokenResponse);
48
+
49
+ // check
50
+ if (!tokenResponse) {
51
+ req.logger.error(methodName, 'tokenResponse is null');
52
+ return;
53
+ }
54
+ if (tokenResponse.status !== 200) {
55
+ req.logger.error(methodName, 'tokenResponse.status !== 200', tokenResponse.status);
56
+ return;
57
+ }
58
+ if (!tokenResponse.data) {
59
+ req.logger.error(methodName, 'tokenResponse.data is null');
60
+ return;
61
+ }
62
+ if (!tokenResponse.data.access_token || !tokenResponse.data.token_type) {
63
+ req.logger.error(methodName, 'tokenResponse.data.access_token is null or tokenResponse.data.token_type is null');
64
+ return;
65
+ }
66
+
67
+ // get user
68
+ req.logger.info(methodName, 'get token success');
69
+ const userUrl = global.QZ_CONFIG.github.userUrl;
70
+ const userConfig = {
71
+ headers: {
72
+ Authorization: `${tokenResponse.data.token_type} ${tokenResponse.data.access_token}`,
73
+ Accept: 'application/json',
74
+ },
75
+ };
76
+ const userResponse = await get(userUrl, userConfig);
77
+
78
+ // check
79
+ if (!userResponse) {
80
+ req.logger.error(methodName, 'userResponse is null');
81
+ return;
82
+ }
83
+ if (userResponse.status !== 200) {
84
+ req.logger.error(methodName, 'userResponse.status !== 200', userResponse.status);
85
+ return;
86
+ }
87
+ if (!userResponse.data) {
88
+ req.logger.error(methodName, 'userResponse.data is null');
89
+ return;
90
+ }
91
+ req.logger.info(methodName, 'get user success');
92
+
93
+ // r
94
+ return userResponse.data;
47
95
  } catch (error) {
48
- console.log(error);
96
+ req.logger.error(methodName, 'error', error);
49
97
  }
50
98
  };
99
+
100
+ // {
101
+ // login: 'uikoo9',
102
+ // id: 10345351,
103
+ // node_id: 'MDQ6VXNlcjEwMzQ1MzUx',
104
+ // avatar_url: 'https://avatars.githubusercontent.com/u/10345351?v=4',
105
+ // gravatar_id: '',
106
+ // url: 'https://api.github.com/users/uikoo9',
107
+ // html_url: 'https://github.com/uikoo9',
108
+ // followers_url: 'https://api.github.com/users/uikoo9/followers',
109
+ // following_url: 'https://api.github.com/users/uikoo9/following{/other_user}',
110
+ // gists_url: 'https://api.github.com/users/uikoo9/gists{/gist_id}',
111
+ // starred_url: 'https://api.github.com/users/uikoo9/starred{/owner}{/repo}',
112
+ // subscriptions_url: 'https://api.github.com/users/uikoo9/subscriptions',
113
+ // organizations_url: 'https://api.github.com/users/uikoo9/orgs',
114
+ // repos_url: 'https://api.github.com/users/uikoo9/repos',
115
+ // events_url: 'https://api.github.com/users/uikoo9/events{/privacy}',
116
+ // received_events_url: 'https://api.github.com/users/uikoo9/received_events',
117
+ // type: 'User',
118
+ // user_view_type: 'private',
119
+ // site_admin: false,
120
+ // name: null,
121
+ // company: null,
122
+ // blog: '',
123
+ // location: null,
124
+ // email: 'uikoo9@qq.com',
125
+ // hireable: null,
126
+ // bio: null,
127
+ // twitter_username: null,
128
+ // notification_email: 'uikoo9@qq.com',
129
+ // public_repos: 27,
130
+ // public_gists: 0,
131
+ // followers: 91,
132
+ // following: 4,
133
+ // created_at: '2014-12-30T03:11:05Z',
134
+ // updated_at: '2026-01-29T09:08:41Z',
135
+ // private_gists: 0,
136
+ // total_private_repos: 33,
137
+ // owned_private_repos: 33,
138
+ // disk_usage: 1026748,
139
+ // collaborators: 4,
140
+ // two_factor_authentication: true,
141
+ // plan: {
142
+ // name: 'free',
143
+ // space: 976562499,
144
+ // collaborators: 0,
145
+ // private_repos: 10000
146
+ // }
147
+ // }