forked from Mirrors/elk
3b92b27cc8
Co-authored-by: Daniel Roe <daniel@roe.dev>
31 lines
793 B
TypeScript
31 lines
793 B
TypeScript
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
|
|
|
|
// 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,
|
|
}),
|
|
},
|
|
}
|
|
})
|