Skip to content

Commit c58d77a

Browse files
authored
🐛 fix: fix wechat login error with next-auth (lobehub#6585)
1 parent 876292b commit c58d77a

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/libs/next-auth/sso-providers/wechat.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import WeChat from '@auth/core/providers/wechat';
1+
import WeChat, { WeChatProfile } from '@auth/core/providers/wechat';
22

33
import { CommonProviderConfig } from './sso.config';
44

@@ -9,7 +9,7 @@ const provider = {
99
clientId: process.env.AUTH_WECHAT_ID,
1010
clientSecret: process.env.AUTH_WECHAT_SECRET,
1111
platformType: 'WebsiteApp',
12-
profile: (profile) => {
12+
profile: (profile: WeChatProfile) => {
1313
return {
1414
email: null,
1515
id: profile.unionid,
@@ -18,6 +18,18 @@ const provider = {
1818
providerAccountId: profile.unionid,
1919
};
2020
},
21+
style: { bg: '#fff', logo: 'https://authjs.dev/img/providers/wechat.svg', text: '#000' },
22+
token: {
23+
async conform(response: Response) {
24+
const data = await response.json();
25+
console.log('wechat data:', data);
26+
return new Response(JSON.stringify({ ...data, token_type: 'bearer' }), {
27+
headers: { 'Content-Type': 'application/json' },
28+
});
29+
},
30+
params: { appid: process.env.AUTH_WECHAT_ID, secret: process.env.AUTH_WECHAT_SECRET },
31+
url: 'https://api.weixin.qq.com/sns/oauth2/access_token',
32+
},
2133
}),
2234
};
2335

0 commit comments

Comments
 (0)