Initial commit from monorepo
This commit is contained in:
32
app/plugins/chatwoot.client.ts
Normal file
32
app/plugins/chatwoot.client.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
export default defineNuxtPlugin(() => {
|
||||
const loadChatwoot = () => {
|
||||
if (document.getElementById('chatwoot-sdk')) return
|
||||
|
||||
const baseUrl = 'https://chatwoot.optovia.ru'
|
||||
const script = document.createElement('script')
|
||||
script.id = 'chatwoot-sdk'
|
||||
script.src = `${baseUrl}/packs/js/sdk.js`
|
||||
script.async = true
|
||||
script.defer = true
|
||||
script.onload = () => {
|
||||
window.chatwootSDK?.run({
|
||||
websiteToken: 'bc668ge3hM5ZpPeUgGEV1ZU9',
|
||||
baseUrl
|
||||
})
|
||||
}
|
||||
|
||||
if (document.body) {
|
||||
document.body.appendChild(script)
|
||||
} else {
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
document.body?.appendChild(script)
|
||||
}, { once: true })
|
||||
}
|
||||
}
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', loadChatwoot, { once: true })
|
||||
} else {
|
||||
loadChatwoot()
|
||||
}
|
||||
})
|
||||
8
app/plugins/logto-tokens.server.ts
Normal file
8
app/plugins/logto-tokens.server.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Server plugin to initialize Logto tokens on SSR.
|
||||
* Fetches all access tokens and stores in useState for client hydration.
|
||||
*/
|
||||
export default defineNuxtPlugin(async () => {
|
||||
const { initTokens } = useLogtoTokens()
|
||||
await initTokens()
|
||||
})
|
||||
15
app/plugins/logto-user.server.ts
Normal file
15
app/plugins/logto-user.server.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
export default defineNuxtPlugin(() => {
|
||||
const nuxtApp = useNuxtApp()
|
||||
const logtoUser = nuxtApp.ssrContext?.event.context.logtoUser ?? null
|
||||
const orgId = (logtoUser as { organizations?: string[] } | null)?.organizations?.[0] ?? null
|
||||
|
||||
const userState = useState('logto-user', () => null)
|
||||
const orgState = useState<string | null>('logto-org-id', () => null)
|
||||
|
||||
if (logtoUser) {
|
||||
userState.value = logtoUser
|
||||
}
|
||||
if (orgId) {
|
||||
orgState.value = orgId
|
||||
}
|
||||
})
|
||||
17
app/plugins/me.server.ts
Normal file
17
app/plugins/me.server.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { useLocationStore } from '~/stores/location'
|
||||
|
||||
export default defineNuxtPlugin(() => {
|
||||
const nuxtApp = useNuxtApp()
|
||||
const me = nuxtApp.ssrContext?.event.context.me ?? null
|
||||
const state = useState('me', () => null)
|
||||
|
||||
if (me) {
|
||||
state.value = me
|
||||
|
||||
// Заполнить locationStore сразу на сервере для SSR
|
||||
const locationStore = useLocationStore()
|
||||
if (me.activeTeam?.selectedLocation) {
|
||||
locationStore.setFromUserData(me.activeTeam.selectedLocation)
|
||||
}
|
||||
}
|
||||
})
|
||||
22
app/plugins/sentry.client.ts
Normal file
22
app/plugins/sentry.client.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import * as Sentry from '@sentry/vue'
|
||||
|
||||
export default defineNuxtPlugin((nuxtApp) => {
|
||||
const config = useRuntimeConfig()
|
||||
const dsn = config.public.sentryDsn
|
||||
|
||||
if (!dsn) {
|
||||
return
|
||||
}
|
||||
|
||||
Sentry.init({
|
||||
app: nuxtApp.vueApp,
|
||||
dsn,
|
||||
integrations: [
|
||||
Sentry.browserTracingIntegration({ router: nuxtApp.$router }),
|
||||
Sentry.replayIntegration()
|
||||
],
|
||||
tracesSampleRate: 0.1,
|
||||
replaysSessionSampleRate: 0.1,
|
||||
replaysOnErrorSampleRate: 1.0
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user