mirror of
https://github.com/elk-zone/elk.git
synced 2024-09-06 20:29:08 +01:00
28 lines
754 B
TypeScript
28 lines
754 B
TypeScript
export default defineNuxtPlugin(async (nuxtApp) => {
|
|
const masto = createMasto()
|
|
publicServer.value = publicServer.value || useRuntimeConfig().public.defaultServer
|
|
|
|
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,
|
|
}
|
|
: currentUser.value
|
|
|
|
nuxtApp.hook('app:suspense:resolve', () => {
|
|
// TODO: improve upstream to make this synchronous (delayed auth)
|
|
if (!masto.loggedIn.value)
|
|
masto.loginTo(user)
|
|
})
|
|
}
|
|
|
|
return {
|
|
provide: {
|
|
masto,
|
|
},
|
|
}
|
|
})
|