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

25 lines
641 B
TypeScript
Raw Normal View History

2022-11-15 14:29:46 +00:00
import { stringifyQuery } from 'ufo'
import { getApp, getRedirectURI } from '~/server/shared'
2022-11-15 14:29:46 +00:00
export default defineEventHandler(async (event) => {
const { server } = getRouterParams(event)
2022-11-27 18:44:19 +00:00
const app = await getApp(server)
2022-11-15 14:29:46 +00:00
if (!app) {
throw createError({
statusCode: 400,
statusMessage: `App not registered for server: ${server}`,
})
2022-11-15 14:29:46 +00:00
}
const query = stringifyQuery({
client_id: app.client_id,
scope: 'read write follow push',
redirect_uri: getRedirectURI(server),
2022-11-15 14:29:46 +00:00
response_type: 'code',
})
const url = `https://${server}/oauth/authorize?${query}`
await sendRedirect(event, url, 302)
2022-11-15 14:29:46 +00:00
})