Skip to content

Commit

Permalink
fix: GitHub code function
Browse files Browse the repository at this point in the history
Signed-off-by: 0x73746F66 <[email protected]>
  • Loading branch information
0x73746F66 committed Jun 11, 2024
1 parent daecb34 commit 93570a5
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions functions/github/install/[installation_id]/[code].js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,20 @@ export async function onRequestGet(context) {
}).toString()
const resp = await fetch(url, { method })
const text = await resp.text()
console.log('text', text)
// const data = JSON.parse(await resp.text())
// const info = await env.d1db.prepare('INSERT INTO integration_github (installation_id, memberEmail, access_key) VALUES (?1, ?2, ?3)')
// .bind(token, session.memberEmail, data.access_token)
// .run()
console.log(`/github/install installation_id=${params?.installation_id} kid=${token}`)
return Response.json({})
const data = Object.fromEntries(text.split('&').map(item => item.split('=').map(decodeURIComponent)))
if (data?.error) {
console.log(data)
throw Error(data.error)
}
if (!data?.access_token) {
console.log(data)
throw Error('OAuth response invalid')
}
const info = await env.d1db.prepare('INSERT INTO integration_github (installation_id, memberEmail, access_key) VALUES (?1, ?2, ?3)')
.bind(token, session.memberEmail, data.access_token)
.run()
console.log(`/github/install installation_id=${params?.installation_id} kid=${token}`, info)
return Response.json(info)
}
return Response.json({ 'err': 'OAuth authorization code not provided' })
}

0 comments on commit 93570a5

Please sign in to comment.