1
0
Fork 1
mirror of https://github.com/elk-zone/elk.git synced 2024-11-05 08:29:57 +00:00
elk/plugins/masto.ts

32 lines
793 B
TypeScript
Raw Normal View History

import type { MastoClient } from 'masto'
import { currentUser } from '../composables/users'
export default defineNuxtPlugin(async () => {
let masto!: MastoClient
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)
masto = await loginTo(user)
}
catch {
// Show error page when Mastodon server is down
showError({
fatal: true,
statusMessage: 'Could not log into account.',
})
}
return {
provide: {
masto: shallowReactive({
replace(api: MastoClient) { this.api = api },
api: masto,
}),
},
}
})