Vue3: migrating from vuex to Pinia (#249)
* Vue3: migrating from vuex to Pinia * toggle input fixes * update configureCompat --------- Co-authored-by: Forms Dev <chirag+new@notionforms.io>
This commit is contained in:
5
resources/js/middleware/admin.js
vendored
5
resources/js/middleware/admin.js
vendored
@@ -1,7 +1,8 @@
|
||||
import store from '~/store'
|
||||
import { useAuthStore } from '../stores/auth';
|
||||
|
||||
export default (to, from, next) => {
|
||||
if (!store.getters['auth/user'].admin) {
|
||||
const authStore = useAuthStore()
|
||||
if (!authStore.user?.admin) {
|
||||
next({ name: 'home' })
|
||||
} else {
|
||||
next()
|
||||
|
||||
5
resources/js/middleware/auth.js
vendored
5
resources/js/middleware/auth.js
vendored
@@ -1,8 +1,9 @@
|
||||
import store from '~/store'
|
||||
import { useAuthStore } from '../stores/auth';
|
||||
import Cookies from 'js-cookie'
|
||||
|
||||
export default async (to, from, next) => {
|
||||
if (!store.getters['auth/check']) {
|
||||
const authStore = useAuthStore()
|
||||
if (!authStore.check) {
|
||||
Cookies.set('intended_url', to.path)
|
||||
|
||||
next({ name: 'login' })
|
||||
|
||||
11
resources/js/middleware/check-auth.js
vendored
11
resources/js/middleware/check-auth.js
vendored
@@ -1,4 +1,4 @@
|
||||
import store from '~/store'
|
||||
import { useAuthStore } from '../stores/auth';
|
||||
import * as Sentry from '@sentry/vue'
|
||||
|
||||
export function initCrisp (user) {
|
||||
@@ -36,12 +36,13 @@ export function initSentry (user) {
|
||||
}
|
||||
|
||||
export default async (to, from, next) => {
|
||||
if (!store.getters['auth/check'] &&
|
||||
store.getters['auth/token'] !== null &&
|
||||
store.getters['auth/token'] !== undefined
|
||||
const authStore = useAuthStore()
|
||||
if (!authStore.check &&
|
||||
authStore.token !== null &&
|
||||
authStore.token !== undefined
|
||||
) {
|
||||
try {
|
||||
store.dispatch('auth/fetchUser').then((user) => {
|
||||
authStore.fetchUser().then((user) => {
|
||||
initCrisp(user)
|
||||
initSentry(user)
|
||||
})
|
||||
|
||||
5
resources/js/middleware/guest.js
vendored
5
resources/js/middleware/guest.js
vendored
@@ -1,7 +1,8 @@
|
||||
import store from '~/store'
|
||||
import { useAuthStore } from '../stores/auth';
|
||||
|
||||
export default (to, from, next) => {
|
||||
if (store.getters['auth/check']) {
|
||||
const authStore = useAuthStore()
|
||||
if (authStore.check) {
|
||||
next({ name: 'home' })
|
||||
} else {
|
||||
next()
|
||||
|
||||
5
resources/js/middleware/notion-connection.js
vendored
5
resources/js/middleware/notion-connection.js
vendored
@@ -1,7 +1,8 @@
|
||||
import store from '~/store'
|
||||
import { useAuthStore } from '../stores/auth';
|
||||
|
||||
export default async (to, from, next) => {
|
||||
if (store.getters['auth/check'] && store.getters['auth/user'].workspaces_count === 0) {
|
||||
const authStore = useAuthStore()
|
||||
if (authStore.check && authStore.user?.workspaces_count === 0) {
|
||||
if ([
|
||||
'forms.create',
|
||||
'forms.show',
|
||||
|
||||
9
resources/js/middleware/role.js
vendored
9
resources/js/middleware/role.js
vendored
@@ -1,4 +1,4 @@
|
||||
import store from '~/store'
|
||||
import { useAuthStore } from '../stores/auth';
|
||||
|
||||
/**
|
||||
* This is middleware to check the current user role.
|
||||
@@ -7,14 +7,13 @@ import store from '~/store'
|
||||
*/
|
||||
|
||||
export default (to, from, next, roles) => {
|
||||
// Grab the user
|
||||
const user = store.getters['auth/user']
|
||||
|
||||
const authStore = useAuthStore()
|
||||
|
||||
// Split roles into an array
|
||||
roles = roles.split(',')
|
||||
|
||||
// Check if the user has one of the required roles...
|
||||
if (!roles.includes(user.role)) {
|
||||
if (!roles.includes(authStore.user?.role)) {
|
||||
next('/unauthorized')
|
||||
}
|
||||
|
||||
|
||||
5
resources/js/middleware/subscribed.js
vendored
5
resources/js/middleware/subscribed.js
vendored
@@ -1,7 +1,8 @@
|
||||
import store from '~/store'
|
||||
import { useAuthStore } from '../stores/auth';
|
||||
|
||||
export default (to, from, next) => {
|
||||
if (!store.getters['auth/user'].is_subscribed) {
|
||||
const authStore = useAuthStore()
|
||||
if (!authStore.user?.is_subscribed) {
|
||||
next({ name: 'pricing' })
|
||||
} else {
|
||||
next()
|
||||
|
||||
Reference in New Issue
Block a user