1
0
mirror of https://github.com/elk-zone/elk synced 2024-12-19 17:18:00 +09:00
elk/plugins/masto.ts
patak baa2696d31
feat: re-apply timelines loading optimization (#524)
Co-authored-by: Daniel Roe <daniel@roe.dev>
2022-12-26 06:39:18 +01:00

33 lines
892 B
TypeScript

export default defineNuxtPlugin(async (nuxtApp) => {
const masto = createMasto()
if (process.client) {
const { query, path } = useRoute()
const router = useRouter()
const user = typeof query.server === 'string' && typeof query.token === 'string'
? {
server: query.server,
token: query.token,
vapidKey: typeof query.vapid_key === 'string' ? query.vapid_key : undefined,
}
: currentUser.value
nuxtApp.hook('app:suspense:resolve', () => {
// TODO: improve upstream to make this synchronous (delayed auth)
if (!masto.loggedIn.value) {
masto.loginTo(user).then(() => {
// This only cleans up the URL; page content should stay the same
if (path === '/signin/callback')
router.push('/home')
})
}
})
}
return {
provide: {
masto,
},
}
})