2022-12-17 19:55:29 +03:00
|
|
|
export default defineNuxtPlugin(async (nuxtApp) => {
|
2022-12-21 00:03:15 +03:00
|
|
|
const masto = createMasto()
|
2023-01-08 00:38:31 +03:00
|
|
|
publicServer.value = publicServer.value || useRuntimeConfig().public.defaultServer
|
2022-12-17 19:55:29 +03:00
|
|
|
|
|
|
|
if (process.client) {
|
2022-12-26 10:33:14 +03:00
|
|
|
const { query } = useRoute()
|
2022-11-27 18:13:04 +03:00
|
|
|
const user = typeof query.server === 'string' && typeof query.token === 'string'
|
2022-12-18 02:29:16 +03:00
|
|
|
? {
|
|
|
|
server: query.server,
|
|
|
|
token: query.token,
|
|
|
|
vapidKey: typeof query.vapid_key === 'string' ? query.vapid_key : undefined,
|
|
|
|
}
|
2022-11-27 18:13:04 +03:00
|
|
|
: currentUser.value
|
2022-11-26 22:33:36 +03:00
|
|
|
|
2022-12-17 19:55:29 +03:00
|
|
|
nuxtApp.hook('app:suspense:resolve', () => {
|
|
|
|
// TODO: improve upstream to make this synchronous (delayed auth)
|
2022-12-26 10:33:14 +03:00
|
|
|
if (!masto.loggedIn.value)
|
|
|
|
masto.loginTo(user)
|
2022-11-26 18:42:58 +03:00
|
|
|
})
|
|
|
|
}
|
2022-11-28 12:01:14 +03:00
|
|
|
|
|
|
|
return {
|
|
|
|
provide: {
|
2022-12-17 19:55:29 +03:00
|
|
|
masto,
|
2022-11-28 12:01:14 +03:00
|
|
|
},
|
|
|
|
}
|
2022-11-26 18:42:58 +03:00
|
|
|
})
|