mirror of
https://github.com/elk-zone/elk.git
synced 2024-11-19 23:40:07 +00:00
refactor: use h3 utils + event in server apis
This commit is contained in:
parent
40a510f43d
commit
0f0acd4824
2 changed files with 10 additions and 19 deletions
|
@ -1,12 +1,12 @@
|
||||||
import { stringifyQuery } from 'ufo'
|
import { stringifyQuery } from 'ufo'
|
||||||
import { HOST_DOMAIN, getApp } from '~/server/shared'
|
import { HOST_DOMAIN, getApp } from '~/server/shared'
|
||||||
|
|
||||||
export default defineEventHandler(async ({ context, res }) => {
|
export default defineEventHandler(async (event) => {
|
||||||
const server = context.params.server
|
const server = event.context.params.server
|
||||||
const app = await getApp(HOST_DOMAIN, server)
|
const app = await getApp(HOST_DOMAIN, server)
|
||||||
|
|
||||||
if (!app) {
|
if (!app) {
|
||||||
res.statusCode = 400
|
setResponseStatus(400)
|
||||||
return `App not registered for server: ${server}`
|
return `App not registered for server: ${server}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,8 +18,5 @@ export default defineEventHandler(async ({ context, res }) => {
|
||||||
})
|
})
|
||||||
const url = `https://${server}/oauth/authorize?${query}`
|
const url = `https://${server}/oauth/authorize?${query}`
|
||||||
|
|
||||||
res.writeHead(302, {
|
await sendRedirect(event, url, 302)
|
||||||
Location: url,
|
|
||||||
})
|
|
||||||
res.end()
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,18 +1,16 @@
|
||||||
import { getQuery } from 'ufo'
|
|
||||||
import { stringifyQuery } from 'vue-router'
|
import { stringifyQuery } from 'vue-router'
|
||||||
import { HOST_DOMAIN, getApp } from '~/server/shared'
|
import { HOST_DOMAIN, getApp } from '~/server/shared'
|
||||||
|
|
||||||
export default defineEventHandler(async ({ context, req, res }) => {
|
export default defineEventHandler(async (event) => {
|
||||||
const server = context.params.server
|
const server = event.context.params.server
|
||||||
const app = await getApp(HOST_DOMAIN, server)
|
const app = await getApp(HOST_DOMAIN, server)
|
||||||
|
|
||||||
if (!app) {
|
if (!app) {
|
||||||
res.statusCode = 400
|
setResponseStatus(400)
|
||||||
return `App not registered for server: ${server}`
|
return `App not registered for server: ${server}`
|
||||||
}
|
}
|
||||||
|
|
||||||
const query = getQuery(req.url!)
|
const { code } = getQuery(event)
|
||||||
const code = query.code
|
|
||||||
|
|
||||||
const result: any = await $fetch(`https://${server}/oauth/token`, {
|
const result: any = await $fetch(`https://${server}/oauth/token`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
@ -26,10 +24,6 @@ export default defineEventHandler(async ({ context, req, res }) => {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
res.writeHead(302, {
|
const url = `${HOST_DOMAIN}/signin/callback?${stringifyQuery({ server, token: result.access_token })}`
|
||||||
Location: `${HOST_DOMAIN}/signin/callback?${stringifyQuery({ server, token: result.access_token })}`,
|
await sendRedirect(event, url, 302)
|
||||||
})
|
|
||||||
res.end()
|
|
||||||
|
|
||||||
return result
|
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue