1
0
Fork 1
mirror of https://github.com/elk-zone/elk.git synced 2024-11-14 21:09:58 +00:00
elk/plugins/masto.ts

33 lines
776 B
TypeScript
Raw Normal View History

import { login } from 'masto'
import { currentUser } from '../composables/users'
import { DEFAULT_SERVER } from '~/constants'
export default defineNuxtPlugin(async () => {
try {
2022-11-26 19:33:36 +00:00
const accessToken = currentUser.value?.token
// TODO: improve upstream to make this synchronous (delayed auth)
const masto = await login({
url: `https://${currentUser.value?.server || DEFAULT_SERVER}`,
2022-11-26 19:33:36 +00:00
accessToken,
})
2022-11-26 19:33:36 +00:00
if (accessToken)
masto.accounts.verifyCredentials().catch(() => signout())
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.',
})
}
})