elk/plugins/masto.ts

28 lines
693 B
TypeScript
Raw Permalink Normal View History

export default defineNuxtPlugin(async (nuxtApp) => {
const masto = createMasto()
if (process.client) {
const { query } = useRoute()
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,
2023-01-03 04:23:16 +03:00
guest: false,
}
: currentUser.value
2022-11-26 22:33:36 +03:00
nuxtApp.hook('app:suspense:resolve', () => {
// TODO: improve upstream to make this synchronous (delayed auth)
if (!masto.loggedIn.value)
masto.loginTo(user)
})
}
return {
provide: {
masto,
},
}
})