elk/plugins/masto.ts

32 wiersze
838 B
TypeScript
Czysty Zwykły widok Historia

import type { MastoClient } from 'masto'
import { currentUser } from '../composables/users'
export default defineNuxtPlugin(async () => {
try {
const { query } = useRoute()
const user = typeof query.server === 'string' && typeof query.token === 'string'
? { server: query.server, token: query.token }
: currentUser.value
2022-11-26 19:33:36 +00:00
// TODO: improve upstream to make this synchronous (delayed auth)
const masto = await loginTo(user) as MastoClient
2022-11-26 19:33:36 +00:00
return {
provide: {
masto: shallowReactive({
replace(api: MastoClient) { this.api = api },
api: masto,
}),
},
}
}
catch {
// TODO: handle error
// Show error page when Mastodon server is down
throw createError({
fatal: true,
statusMessage: 'Could not log into account.',
})
}
})