mirror of
https://github.com/elk-zone/elk.git
synced 2024-11-27 19:57:50 +03:00
chore: remove /invite
route preparatory to launch
This commit is contained in:
parent
3f9e39d244
commit
3a66944080
3 changed files with 0 additions and 84 deletions
|
@ -5,7 +5,6 @@ import {
|
||||||
toNodeListener,
|
toNodeListener,
|
||||||
} from 'h3'
|
} from 'h3'
|
||||||
import { createFetch } from 'ofetch'
|
import { createFetch } from 'ofetch'
|
||||||
import { parseURL } from 'ufo'
|
|
||||||
import {
|
import {
|
||||||
createCall,
|
createCall,
|
||||||
createFetch as createLocalFetch,
|
createFetch as createLocalFetch,
|
||||||
|
@ -26,13 +25,10 @@ const handlers = [
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
const { protocol, host } = parseURL(window.location.href)
|
|
||||||
|
|
||||||
// @ts-expect-error undeclared global window property
|
// @ts-expect-error undeclared global window property
|
||||||
window.__NUXT__.config = {
|
window.__NUXT__.config = {
|
||||||
// @ts-expect-error undeclared global window property
|
// @ts-expect-error undeclared global window property
|
||||||
...window.__NUXT__.config,
|
...window.__NUXT__.config,
|
||||||
deployUrl: `${protocol}//${host}`,
|
|
||||||
storage: {},
|
storage: {},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,25 +71,11 @@ export default defineNuxtConfig({
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
runtimeConfig: {
|
runtimeConfig: {
|
||||||
deployUrl: !isCI
|
|
||||||
? 'http://localhost:5314'
|
|
||||||
: isPreview
|
|
||||||
? process.env.DEPLOY_PRIME_URL
|
|
||||||
: 'https://elk.zone',
|
|
||||||
cloudflare: {
|
cloudflare: {
|
||||||
accountId: '',
|
accountId: '',
|
||||||
namespaceId: '',
|
namespaceId: '',
|
||||||
apiToken: '',
|
apiToken: '',
|
||||||
},
|
},
|
||||||
discord: {
|
|
||||||
inviteUrl: 'https://chat.elk.zone',
|
|
||||||
},
|
|
||||||
github: {
|
|
||||||
// oauth flow
|
|
||||||
clientId: '',
|
|
||||||
clientSecret: '',
|
|
||||||
inviteToken: '',
|
|
||||||
},
|
|
||||||
public: {
|
public: {
|
||||||
env: '', // set in build-env module
|
env: '', // set in build-env module
|
||||||
buildInfo: {} as BuildInfo, // set in build-env module
|
buildInfo: {} as BuildInfo, // set in build-env module
|
||||||
|
|
|
@ -1,66 +0,0 @@
|
||||||
const query = (accessToken: string, query: string) =>
|
|
||||||
$fetch<{ data: any }>('https://api.github.com/graphql', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: { Authorization: `Bearer ${accessToken}` },
|
|
||||||
body: { query },
|
|
||||||
})
|
|
||||||
|
|
||||||
export default defineEventHandler(async (event) => {
|
|
||||||
const { code } = getQuery(event)
|
|
||||||
|
|
||||||
const config = useRuntimeConfig()
|
|
||||||
|
|
||||||
if (!code) {
|
|
||||||
const redirect = `&redirect_uri=${config.deployUrl}/invite`
|
|
||||||
const loginURL = `https://github.com/login/oauth/authorize?client_id=${config.github.clientId}${redirect}`
|
|
||||||
await sendRedirect(event, loginURL)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const { access_token } = await $fetch<{ access_token: string }>(
|
|
||||||
'https://github.com/login/oauth/access_token',
|
|
||||||
{
|
|
||||||
method: 'POST',
|
|
||||||
body: {
|
|
||||||
client_id: config.github.clientId,
|
|
||||||
client_secret: config.github.clientSecret,
|
|
||||||
code,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!access_token) {
|
|
||||||
throw createError({
|
|
||||||
statusCode: 422,
|
|
||||||
statusMessage: 'Authorisation code invalid.',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const id = await query(access_token, '{ viewer { databaseId } }')
|
|
||||||
.then(r => r.data?.viewer.databaseId)
|
|
||||||
|
|
||||||
if (!id) {
|
|
||||||
throw createError({
|
|
||||||
statusCode: 422,
|
|
||||||
statusMessage: 'Access code invalid.',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
await $fetch(
|
|
||||||
'https://api.github.com/orgs/elk-zone/invitations',
|
|
||||||
{
|
|
||||||
method: 'POST',
|
|
||||||
body: { invitee_id: id, role: 'direct_member', team_ids: [7042932] },
|
|
||||||
headers: {
|
|
||||||
'Accept': 'application/vnd.github+json',
|
|
||||||
'Authorization': `Bearer ${config.github.inviteToken}`,
|
|
||||||
'X-GitHub-Api-Version': '2022-11-28',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
return sendRedirect(
|
|
||||||
event,
|
|
||||||
config.discord.inviteUrl,
|
|
||||||
)
|
|
||||||
})
|
|
Loading…
Reference in a new issue