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