refactor: inject masto instance via nuxt app (#134)
This commit is contained in:
parent
5c60497421
commit
39b005899e
26 changed files with 67 additions and 48 deletions
27
plugins/masto.ts
Normal file
27
plugins/masto.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
import { login } from 'masto'
|
||||
import { currentUser } from '../composables/users'
|
||||
import { DEFAULT_SERVER } from '~/constants'
|
||||
|
||||
export default defineNuxtPlugin(async () => {
|
||||
try {
|
||||
// TODO: improve upstream to make this synchronous (delayed auth)
|
||||
const masto = await login({
|
||||
url: `https://${currentUser.value?.server || DEFAULT_SERVER}`,
|
||||
accessToken: currentUser.value?.token || undefined,
|
||||
})
|
||||
|
||||
return {
|
||||
provide: {
|
||||
masto,
|
||||
},
|
||||
}
|
||||
}
|
||||
catch {
|
||||
// TODO: handle error
|
||||
// Show error page when Mastodon server is down
|
||||
throw createError({
|
||||
fatal: true,
|
||||
statusMessage: 'Could not log into account.',
|
||||
})
|
||||
}
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue