forked from TanStack/tanstack.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiscord-github.js
More file actions
45 lines (35 loc) · 1.09 KB
/
Copy pathdiscord-github.js
File metadata and controls
45 lines (35 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { Octokit } from '@octokit/rest'
import { linkSponsorToken } from './discord'
import { getSponsorsAndTiers } from './sponsors'
export async function linkGithubAndDiscordUser({ githubToken, discordToken }) {
let login
try {
const octokit = new Octokit({
auth: githubToken,
useAgent: `TanStack.com ${githubToken}`,
})
const { data } = await octokit.users.getAuthenticated()
login = data.login
} catch (err) {
console.error(err)
throw new Error('Unable to fetch Github user info. Please log in again.')
}
let sponsor
try {
const { sponsors } = await getSponsorsAndTiers()
sponsor = sponsors.find((d) => d.login == login)
} catch (err) {
throw new Error('Unable to fetch sponsor info. Please contact support.')
}
if (!sponsor) {
throw new Error(
`TanStack sponsorship not found for Github user "${login}". Please sign up at https://github.com/sponsors/tannerlinsley`
)
}
const sponsorType = sponsor.tier.meta.sponsorType
const message = await linkSponsorToken({
discordToken,
sponsorType,
})
return message
}