0351d front end linting (#377)
* feat: disable custom script for trial users * after lint fix * frontend linting --------- Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
12
client/middleware/01.check-auth.global.js
vendored
12
client/middleware/01.check-auth.global.js
vendored
@@ -1,15 +1,17 @@
|
||||
import {fetchAllWorkspaces} from "~/stores/workspaces.js";
|
||||
import {opnFetch} from "~/composables/useOpnApi.js";
|
||||
import { fetchAllWorkspaces } from "~/stores/workspaces.js"
|
||||
|
||||
export default defineNuxtRouteMiddleware(async(to, from) => {
|
||||
export default defineNuxtRouteMiddleware(async () => {
|
||||
const authStore = useAuthStore()
|
||||
authStore.initStore(useCookie('token').value, useCookie('admin_token').value)
|
||||
authStore.initStore(useCookie("token").value, useCookie("admin_token").value)
|
||||
|
||||
if (authStore.token && !authStore.user) {
|
||||
const workspaceStore = useWorkspacesStore()
|
||||
|
||||
// Load user data and workspaces
|
||||
const [userDataResponse, workspacesResponse] = await Promise.all([useOpnApi('user'), fetchAllWorkspaces()]);
|
||||
const [userDataResponse, workspacesResponse] = await Promise.all([
|
||||
useOpnApi("user"),
|
||||
fetchAllWorkspaces(),
|
||||
])
|
||||
authStore.setUser(userDataResponse.data.value)
|
||||
workspaceStore.save(workspacesResponse.data.value)
|
||||
}
|
||||
|
||||
4
client/middleware/admin.js
vendored
4
client/middleware/admin.js
vendored
@@ -1,6 +1,6 @@
|
||||
export default defineNuxtRouteMiddleware((to, from) => {
|
||||
export default defineNuxtRouteMiddleware(() => {
|
||||
const authStore = useAuthStore()
|
||||
if (authStore.check && !authStore.user?.admin) {
|
||||
return navigateTo({ name: 'home' })
|
||||
return navigateTo({ name: "home" })
|
||||
}
|
||||
})
|
||||
|
||||
13
client/middleware/api-redirect.global.js
vendored
13
client/middleware/api-redirect.global.js
vendored
@@ -1,11 +1,12 @@
|
||||
|
||||
export default defineNuxtRouteMiddleware((to, from) => {
|
||||
export default defineNuxtRouteMiddleware((to) => {
|
||||
if (import.meta.client) return
|
||||
|
||||
const config = useRuntimeConfig()
|
||||
if (to.fullPath.startsWith('/api')) {
|
||||
const path = to.fullPath.replace('/api', '')
|
||||
return navigateTo(config.public.apiBase + path, { redirectCode: 301, external: true })
|
||||
if (to.fullPath.startsWith("/api")) {
|
||||
const path = to.fullPath.replace("/api", "")
|
||||
return navigateTo(config.public.apiBase + path, {
|
||||
redirectCode: 301,
|
||||
external: true,
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
6
client/middleware/auth.js
vendored
6
client/middleware/auth.js
vendored
@@ -1,8 +1,8 @@
|
||||
export default defineNuxtRouteMiddleware((to, from) => {
|
||||
export default defineNuxtRouteMiddleware((to) => {
|
||||
const authStore = useAuthStore()
|
||||
|
||||
if (!authStore.check) {
|
||||
useCookie('intended_url').value = to.path
|
||||
return navigateTo({ name: 'login' })
|
||||
useCookie("intended_url").value = to.path
|
||||
return navigateTo({ name: "login" })
|
||||
}
|
||||
})
|
||||
|
||||
31
client/middleware/custom-domain.global.js
vendored
31
client/middleware/custom-domain.global.js
vendored
@@ -1,31 +1,39 @@
|
||||
import {customDomainUsed, getDomain, getHost} from "~/lib/utils.js";
|
||||
import { customDomainUsed, getDomain, getHost } from "~/lib/utils.js"
|
||||
|
||||
/**
|
||||
* Added by Caddy when proxying to the app
|
||||
* @type {string}
|
||||
*/
|
||||
const customDomainHeaderName = 'user-custom-domain'
|
||||
const customDomainHeaderName = "user-custom-domain"
|
||||
|
||||
/**
|
||||
* List of routes that can be used with a custom domain
|
||||
* @type {string[]}
|
||||
*/
|
||||
const customDomainAllowedRoutes = ['forms-slug']
|
||||
const customDomainAllowedRoutes = ["forms-slug"]
|
||||
|
||||
function redirectToMainDomain(details = {}) {
|
||||
console.warn('Redirecting to main domain', { reason: 'unknown', ...details})
|
||||
return navigateTo(useRuntimeConfig().public.appUrl + '?utm_source=failed_custom_domain_redirect', { redirectCode: 301, external: true })
|
||||
console.warn("Redirecting to main domain", { reason: "unknown", ...details })
|
||||
return navigateTo(
|
||||
useRuntimeConfig().public.appUrl +
|
||||
"?utm_source=failed_custom_domain_redirect",
|
||||
{ redirectCode: 301, external: true },
|
||||
)
|
||||
}
|
||||
|
||||
export default defineNuxtRouteMiddleware((to, from) => {
|
||||
export default defineNuxtRouteMiddleware((to) => {
|
||||
if (!customDomainUsed()) return
|
||||
|
||||
const config = useRuntimeConfig()
|
||||
|
||||
const customDomainHeaderValue = useRequestHeaders()[customDomainHeaderName]
|
||||
if (import.meta.server && (!customDomainHeaderValue || customDomainHeaderValue !== getDomain(getHost()))) {
|
||||
return redirectToMainDomain( {
|
||||
reason: 'header_mismatch',
|
||||
if (
|
||||
import.meta.server &&
|
||||
(!customDomainHeaderValue ||
|
||||
customDomainHeaderValue !== getDomain(getHost()))
|
||||
) {
|
||||
return redirectToMainDomain({
|
||||
reason: "header_mismatch",
|
||||
customDomainHeaderValue: customDomainHeaderValue,
|
||||
host: getDomain(getHost()),
|
||||
})
|
||||
@@ -34,15 +42,14 @@ export default defineNuxtRouteMiddleware((to, from) => {
|
||||
if (!config.public.customDomainsEnabled) {
|
||||
// If custom domain not allowed, redirect
|
||||
return redirectToMainDomain({
|
||||
reason: 'custom_domains_disabled'
|
||||
reason: "custom_domains_disabled",
|
||||
})
|
||||
}
|
||||
|
||||
if (!customDomainAllowedRoutes.includes(to.name)) {
|
||||
// Custom domain only allowed for form url
|
||||
return redirectToMainDomain({
|
||||
reason: 'route_not_allowed'
|
||||
reason: "route_not_allowed",
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
7
client/middleware/guest.js
vendored
7
client/middleware/guest.js
vendored
@@ -1,9 +1,8 @@
|
||||
|
||||
export default defineNuxtRouteMiddleware((to, from) => {
|
||||
export default defineNuxtRouteMiddleware(() => {
|
||||
const authStore = useAuthStore()
|
||||
|
||||
if (authStore.check) {
|
||||
console.log('redirecting to home')
|
||||
return navigateTo({ name: 'home' })
|
||||
console.log("redirecting to home")
|
||||
return navigateTo({ name: "home" })
|
||||
}
|
||||
})
|
||||
|
||||
4
client/middleware/moderator.js
vendored
4
client/middleware/moderator.js
vendored
@@ -1,6 +1,6 @@
|
||||
export default defineNuxtRouteMiddleware((to, from) => {
|
||||
export default defineNuxtRouteMiddleware(() => {
|
||||
const authStore = useAuthStore()
|
||||
if (authStore.check && !authStore.user?.moderator) {
|
||||
return navigateTo({ name: 'home' })
|
||||
return navigateTo({ name: "home" })
|
||||
}
|
||||
})
|
||||
|
||||
4
client/middleware/subscribed.js
vendored
4
client/middleware/subscribed.js
vendored
@@ -1,7 +1,7 @@
|
||||
export default defineNuxtRouteMiddleware((to, from) => {
|
||||
export default defineNuxtRouteMiddleware(() => {
|
||||
const authStore = useAuthStore()
|
||||
|
||||
if (authStore.check && !authStore.user?.is_subscribed) {
|
||||
return navigateTo({ name: 'pricing' })
|
||||
return navigateTo({ name: "pricing" })
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user