Initial commit

This commit is contained in:
Julien Nahum
2022-09-20 21:59:52 +02:00
commit f8e6cd4dd6
479 changed files with 77078 additions and 0 deletions

9
resources/js/middleware/admin.js vendored Normal file
View File

@@ -0,0 +1,9 @@
import store from '~/store'
export default (to, from, next) => {
if (!store.getters['auth/user'].admin) {
next({ name: 'home' })
} else {
next()
}
}

12
resources/js/middleware/auth.js vendored Normal file
View File

@@ -0,0 +1,12 @@
import store from '~/store'
import Cookies from 'js-cookie'
export default async (to, from, next) => {
if (!store.getters['auth/check']) {
Cookies.set('intended_url', to.path)
next({ name: 'login' })
} else {
next()
}
}

33
resources/js/middleware/check-auth.js vendored Normal file
View File

@@ -0,0 +1,33 @@
import store from '~/store'
export function initCrisp (user) {
return new Promise((resolve, reject) => {
const intervalId = window.setInterval(function () {
if (window.$crisp) {
window.$crisp.push(['set', 'user:email', user.email])
window.$crisp.push(['set', 'user:nickname', user.name])
window.$crisp.push(['set', 'session:data', [[
['pro-subscription', user.is_subscribed],
['id', user.id]
]]])
window.clearInterval(intervalId)
resolve()
}
}, 500)
})
}
export default async (to, from, next) => {
if (!store.getters['auth/check'] &&
store.getters['auth/token'] !== null &&
store.getters['auth/token'] !== undefined
) {
try {
const user = await store.dispatch('auth/fetchUser')
initCrisp(user)
} catch (e) {
console.log(e, 'error')
}
}
next()
}

9
resources/js/middleware/guest.js vendored Normal file
View File

@@ -0,0 +1,9 @@
import store from '~/store'
export default (to, from, next) => {
if (store.getters['auth/check']) {
next({ name: 'home' })
} else {
next()
}
}

8
resources/js/middleware/locale.js vendored Normal file
View File

@@ -0,0 +1,8 @@
import store from '~/store'
import { loadMessages } from '~/plugins/i18n'
export default async (to, from, next) => {
await loadMessages(store.getters['lang/locale'])
next()
}

View File

@@ -0,0 +1,17 @@
import store from '~/store'
export default async (to, from, next) => {
/* if (store.getters['auth/check'] && store.getters['auth/user'].workspaces_count === 0) {
if ([
'forms.create',
'forms.show',
'forms.edit',
'home'
].includes(to.name)
) {
next({ name: 'onboarding' })
}
}*/
next()
}

22
resources/js/middleware/role.js vendored Normal file
View File

@@ -0,0 +1,22 @@
import store from '~/store'
/**
* This is middleware to check the current user role.
*
* middleware: 'role:admin,manager',
*/
export default (to, from, next, roles) => {
// Grab the user
const user = store.getters['auth/user']
// Split roles into an array
roles = roles.split(',')
// Check if the user has one of the required roles...
if (!roles.includes(user.role)) {
next('/unauthorized')
}
next()
}

9
resources/js/middleware/subscribed.js vendored Normal file
View File

@@ -0,0 +1,9 @@
import store from '~/store'
export default (to, from, next) => {
if (!store.getters['auth/user'].is_subscribed) {
next({ name: 'pricing' })
} else {
next()
}
}