Fix sentry nuxt and custom domain redirect
This commit is contained in:
parent
b29cdf8d8a
commit
be43c5cae3
|
@ -28,7 +28,7 @@ class CustomDomainRestriction
|
|||
'success' => false,
|
||||
'message' => 'Invalid domain',
|
||||
'error' => 'invalid_domain',
|
||||
], 401);
|
||||
], 420);
|
||||
}
|
||||
|
||||
// Check if domain is different from current domain
|
||||
|
@ -43,7 +43,7 @@ class CustomDomainRestriction
|
|||
'success' => false,
|
||||
'message' => 'Unknown domain',
|
||||
'error' => 'invalid_domain',
|
||||
], 400);
|
||||
], 420);
|
||||
}
|
||||
|
||||
Workspace::addGlobalScope('domain-restricted', function (Builder $builder) use ($workspace) {
|
||||
|
|
|
@ -42,26 +42,20 @@ export function getOpnRequestsOptions(request, opts) {
|
|||
|
||||
return {
|
||||
baseURL: config.public.apiBase,
|
||||
onResponseError({response}) {
|
||||
async onResponseError({response}) {
|
||||
const authStore = useAuthStore()
|
||||
console.log(response)
|
||||
|
||||
const {status} = response
|
||||
|
||||
if (status === 401) {
|
||||
if (response.body.error && response.body.error === 'invalid_domain' && process.client) {
|
||||
// If invalid domain, redirect to main domain
|
||||
window.location.href = config.public.appUrl + '?utm_source=failed_custom_domain_redirect'
|
||||
return
|
||||
}
|
||||
|
||||
if (authStore.check) {
|
||||
console.log("Logging out due to 401")
|
||||
authStore.logout()
|
||||
useRouter().push({name: 'login'})
|
||||
}
|
||||
}
|
||||
|
||||
if (status >= 500) {
|
||||
} else if (status === 420) {
|
||||
// If invalid domain, redirect to main domain
|
||||
window.location.href = config.public.appUrl + '?utm_source=failed_custom_domain_redirect'
|
||||
} else if (status >= 500) {
|
||||
console.error('Request error', status)
|
||||
}
|
||||
},
|
||||
|
|
|
@ -47,7 +47,7 @@ export const appUrl = (path = '/') => {
|
|||
*/
|
||||
export const getHost = function () {
|
||||
if (process.server) {
|
||||
return useNuxtApp().ssrContext?.event.context.siteConfigNitroOrigin || useNuxtApp().ssrContext?.event.node.req.headers.host
|
||||
return getDomain(useNuxtApp().ssrContext?.event.context.siteConfigNitroOrigin) || useNuxtApp().ssrContext?.event.node.req.headers.host
|
||||
} else {
|
||||
return window.location.host
|
||||
}
|
||||
|
@ -59,6 +59,7 @@ export const getHost = function () {
|
|||
* @returns {*}
|
||||
*/
|
||||
export const getDomain = function (url) {
|
||||
if (url.includes('localhost')) return 'localhost'
|
||||
return (new URL(url)).hostname
|
||||
}
|
||||
|
||||
|
@ -68,7 +69,8 @@ export const getDomain = function (url) {
|
|||
*/
|
||||
export const customDomainUsed = function() {
|
||||
const config = useRuntimeConfig()
|
||||
const appUrl = config.public.appUrl
|
||||
const appDomain = getDomain(config.public.appUrl)
|
||||
const host = getHost()
|
||||
|
||||
return getDomain(getHost()) !== getDomain(appUrl)
|
||||
return host !== appDomain && getDomain(host) !== appDomain
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ export default defineNuxtConfig({
|
|||
'nuxt3-notifications',
|
||||
'nuxt-simple-sitemap',
|
||||
'@nuxt/image',
|
||||
// ... opnformConfig.sentry_dsn ? ['@nuxtjs/sentry'] : [],
|
||||
... process.env.NUXT_PUBLIC_SENTRY_DSN ? ['@nuxtjs/sentry'] : [],
|
||||
],
|
||||
build: {
|
||||
transpile: ["vue-notion"],
|
||||
|
|
Loading…
Reference in New Issue