elk/server/api/[server]/login.ts

23 lines
628 B
TypeScript
Raw Normal View History

2022-11-15 14:29:46 +00:00
import { stringifyQuery } from 'ufo'
import { HOST_DOMAIN, getApp } from '~/server/shared'
2022-11-15 14:29:46 +00:00
export default defineEventHandler(async (event) => {
const server = event.context.params.server
const app = await getApp(HOST_DOMAIN, server)
2022-11-15 14:29:46 +00:00
if (!app) {
setResponseStatus(400)
2022-11-15 14:29:46 +00:00
return `App not registered for server: ${server}`
}
const query = stringifyQuery({
client_id: app.client_id,
scope: 'read write follow push',
redirect_uri: `${HOST_DOMAIN}/api/${server}/oauth`,
response_type: 'code',
})
const url = `https://${server}/oauth/authorize?${query}`
await sendRedirect(event, url, 302)
2022-11-15 14:29:46 +00:00
})