Skip to content

Beautiful Open-Source Form Builder

Fix sentry nuxt and custom domain redirect

Julien Nahumbe43c5cae37f
diff --git a/app/Http/Middleware/CustomDomainRestriction.php b/app/Http/Middleware/CustomDomainRestriction.php
index 3ff5b8b40..31f4b0e8c 100644
--- a/app/Http/Middleware/CustomDomainRestriction.php
+++ b/app/Http/Middleware/CustomDomainRestriction.php
@@ -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) {
diff --git a/client/composables/useOpnApi.js b/client/composables/useOpnApi.js
index e2c0ede4c..77bcd7e13 100644
--- a/client/composables/useOpnApi.js
+++ b/client/composables/useOpnApi.js
@@ -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
+ 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)
}
},
diff --git a/client/lib/utils.js b/client/lib/utils.js
index b6914b82d..f5eaf25a0 100644
--- a/client/lib/utils.js
+++ b/client/lib/utils.js
@@ -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
}
diff --git a/client/nuxt.config.ts b/client/nuxt.config.ts
index 1f96e3963..18c84cdba 100644
--- a/client/nuxt.config.ts
+++ b/client/nuxt.config.ts
@@ -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"],