Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: change page reload and account switch logic #2975

Merged
merged 14 commits into from
Sep 25, 2024
Prev Previous commit
Next Next commit
fix: don't call masto on server side
  • Loading branch information
userquin committed Sep 24, 2024
commit 5da9cb6747ef8b660b1fc0e24adc72e6ecf31bea
39 changes: 22 additions & 17 deletions plugins/masto.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
export default defineNuxtPlugin(() => {
const { params, query } = useRoute()
export default defineNuxtPlugin({
enforce: 'pre',
parallel: import.meta.server,
setup() {
const { params, query } = useRoute()

publicServer.value = params.server as string || useRuntimeConfig().public.defaultServer
publicServer.value = params.server as string || useRuntimeConfig().public.defaultServer

const masto = createMasto()
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 || { server: publicServer.value })
const masto = createMasto()
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 || { server: publicServer.value })

loginTo(masto, user)
if (import.meta.client)
loginTo(masto, user)

return {
provide: {
masto,
},
}
return {
provide: {
masto,
},
}
},
})