Skip to content

Commit 849757a

Browse files
authored
Merge pull request #6945 from FlowFuse/6829-pinia-task-12-account-auth
[6829] Pinia Task 12 - account-auth
2 parents d484b8b + 15378f1 commit 849757a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+552
-216
lines changed

frontend/src/App.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</div>
88
</main>
99
</template>
10-
<template v-else-if="pending">
10+
<template v-else-if="appLoader">
1111
<main class="ff-bg-dark flex-grow flex flex-col">
1212
<div class="w-full mx-auto flex-grow flex flex-col">
1313
<Loading color="white" />
@@ -78,9 +78,11 @@ import PasswordExpired from './pages/PasswordExpired.vue'
7878
import TermsAndConditions from './pages/TermsAndConditions.vue'
7979
import UnverifiedEmail from './pages/UnverifiedEmail.vue'
8080
81+
import { useAccountAuthStore } from '@/stores/account-auth.js'
8182
import { useContextStore } from '@/stores/context.js'
8283
import { useProductBrokersStore } from '@/stores/product-brokers.js'
8384
import { useUxDrawersStore } from '@/stores/ux-drawers.js'
85+
import { useUxLoadingStore } from '@/stores/ux-loading.js'
8486
8587
export default {
8688
name: 'App',
@@ -100,7 +102,9 @@ export default {
100102
},
101103
computed: {
102104
...mapState(useUxDrawersStore, ['hiddenLeftDrawer']),
103-
...mapVuexState('account', ['pending', 'user', 'team', 'offline', 'settings']),
105+
...mapState(useAccountAuthStore, ['user']),
106+
...mapState(useUxLoadingStore, ['appLoader', 'offline']),
107+
...mapVuexState('account', ['team', 'settings']),
104108
loginRequired () {
105109
return this.$route.meta.requiresLogin !== false
106110
},

frontend/src/api/client.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ client.interceptors.response.use(function (response) {
2020

2121
// This is an error response from our own API (or failure to reach it)
2222
// Lazy require to avoid circular dependency:
23-
// api/client.js → store/index.js → account/index.js → routes.js → page components → api modules → api/client.js
24-
// TODO: remove once the `account` Vuex module is migrated to Pinia — replace with a direct import of the Pinia account store.
23+
// api/client.js → stores/account-auth.js → api/user.js → api/client.js
24+
const { useAccountAuthStore } = require('../stores/account-auth.js')
25+
const { useUxLoadingStore } = require('../stores/ux-loading.js')
2526
const store = require('../store/index.js').default
2627
if (error.code === 'ERR_NETWORK') {
2728
// Backend failed to respond
28-
store.dispatch('account/setOffline', true)
29-
} else if (error.response && error.response.status === 401 && !store.state.account.pending && !store.state.account.loginInflight) {
29+
useUxLoadingStore().setOffline(true)
30+
} else if (error.response && error.response.status === 401 && !useUxLoadingStore().appLoader && !useAccountAuthStore().loginInflight) {
3031
// 401 when !pending && !loginInflight means the session has expired
3132
store.dispatch('account/logout')
3233
} else if (error.response && error.response.status === 500) {

frontend/src/components/PageHeader.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ import NotificationsButton from './NotificationsButton.vue'
119119
import TeamSelection from './TeamSelection.vue'
120120
import GlobalSearch from './global-search/GlobalSearch.vue'
121121
122+
import { useAccountAuthStore } from '@/stores/account-auth.js'
122123
import { useUxDrawersStore } from '@/stores/ux-drawers.js'
123124
import { useUxToursStore } from '@/stores/ux-tours.js'
124125
@@ -130,7 +131,8 @@ export default {
130131
return Roles
131132
},
132133
...mapState(useUxDrawersStore, ['leftDrawer', 'hiddenLeftDrawer']),
133-
...mapVuexState('account', ['user', 'team', 'teams']),
134+
...mapState(useAccountAuthStore, ['user']),
135+
...mapVuexState('account', ['team', 'teams']),
134136
...mapGetters('account', ['notifications', 'hasAvailableTeams', 'defaultUserTeam', 'canCreateTeam', 'isTrialAccount', 'featuresCheck']),
135137
navigationOptions () {
136138
return [

frontend/src/components/TeamTypeSelection.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
</template>
2020

2121
<script>
22-
import { mapGetters, mapState } from 'vuex'
22+
23+
import { mapGetters } from 'vuex'
2324
2425
import teamTypesApi from '../api/teamTypes.js'
2526
@@ -38,7 +39,6 @@ export default {
3839
}
3940
},
4041
computed: {
41-
...mapState('account', ['user']),
4242
...mapGetters('account', ['isBillingEnabled'])
4343
},
4444
async created () {

frontend/src/components/TeamTypeTile.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@
3030
</template>
3131

3232
<script>
33-
import { mapState } from 'vuex'
33+
import { mapState } from 'pinia'
34+
import { mapState as mapVuexState } from 'vuex'
3435
3536
import { useHubspotHelper } from '../composables/Hubspot.js'
3637
38+
import { useAccountAuthStore } from '@/stores/account-auth.js'
39+
3740
export default {
3841
name: 'TeamTypeTile',
3942
props: {
@@ -56,7 +59,8 @@ export default {
5659
return { talkToSalesCalendarModal }
5760
},
5861
computed: {
59-
...mapState('account', ['user', 'teams']),
62+
...mapVuexState('account', ['teams']),
63+
...mapState(useAccountAuthStore, ['user']),
6064
pricing: function () {
6165
const billingDescriptionKey = this.billingInterval === 'year' ? 'yrDescription' : 'description'
6266
const billing = this.teamType.properties?.billing?.[billingDescriptionKey]?.split('/')

frontend/src/components/auth/UpdateExpiredPassword.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,19 @@
4040
</template>
4141

4242
<script>
43-
import { mapState } from 'vuex'
43+
import { mapState } from 'pinia'
4444
4545
import userApi from '../../api/user.js'
4646
import store from '../../store/index.js'
4747
import FormRow from '../FormRow.vue'
4848
49+
import { useAccountAuthStore } from '@/stores/account-auth.js'
50+
4951
export default {
5052
name: 'UpdateExpiredPassword',
51-
computed: mapState('account', ['loginError']),
53+
computed: {
54+
...mapState(useAccountAuthStore, ['loginError'])
55+
},
5256
data () {
5357
return {
5458
input: {

frontend/src/components/banners/LicenseBanner.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
<script>
1818
import { ChevronRightIcon, ExclamationCircleIcon } from '@heroicons/vue/outline'
1919
20-
import { mapState } from 'vuex'
20+
import { mapState } from 'pinia'
21+
import { mapState as mapVuexState } from 'vuex'
22+
23+
import { useAccountAuthStore } from '@/stores/account-auth.js'
2124
2225
export default {
2326
name: 'LicenseBanner',
@@ -26,7 +29,8 @@ export default {
2629
ChevronRightIcon
2730
},
2831
computed: {
29-
...mapState('account', ['settings', 'user']),
32+
...mapVuexState('account', ['settings']),
33+
...mapState(useAccountAuthStore, ['user']),
3034
license () {
3135
return this.settings.license || {}
3236
},

frontend/src/components/drawers/navigation/MainNav.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default {
4343
emits: ['option-selected'],
4444
computed: {
4545
...mapState(useUxNavigationStore, ['mainNav', 'mainNavContext']),
46-
...mapVuexState('account', ['user', 'team', 'features', 'notifications']),
46+
...mapVuexState('account', ['team', 'features', 'notifications']),
4747
...mapGetters('account', ['requiresBilling']),
4848
nearestMetaMenu () {
4949
if (this.$route?.meta?.menu) {

frontend/src/pages/Home.vue

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<main class="min-h-full">
3-
<template v-if="pending">
3+
<template v-if="appLoader">
44
<div class="flex-grow flex flex-col items-center justify-center mx-auto text-gray-600 opacity-50">
55
<FlowFuseLogo class="max-w-xs mx-auto w-full" />
66
</div>
@@ -37,14 +37,18 @@
3737

3838
<script>
3939
40-
import { mapGetters, mapState } from 'vuex'
40+
import { mapState } from 'pinia'
41+
import { mapGetters, mapState as mapVuexState } from 'vuex'
4142
4243
import EmptyState from '../components/EmptyState.vue'
4344
4445
import FlowFuseLogo from '../components/Logo.vue'
4546
4647
import TeamTypeSelection from '../components/TeamTypeSelection.vue'
4748
49+
import { useAccountAuthStore } from '@/stores/account-auth.js'
50+
import { useUxLoadingStore } from '@/stores/ux-loading.js'
51+
4852
export default {
4953
name: 'HomePage',
5054
components: {
@@ -58,8 +62,10 @@ export default {
5862
}
5963
},
6064
computed: {
61-
...mapState('account', ['pending', 'user', 'team', 'teams', 'redirectUrlAfterLogin', 'settings']),
65+
...mapVuexState('account', ['team', 'teams', 'settings']),
6266
...mapGetters('account', ['defaultUserTeam']),
67+
...mapState(useAccountAuthStore, ['user', 'redirectUrlAfterLogin']),
68+
...mapState(useUxLoadingStore, ['appLoader']),
6369
canCreateTeam () {
6470
if (this.user.admin) return true
6571
return Object.prototype.hasOwnProperty.call(this.settings, 'team:create') && this.settings['team:create'] === true

frontend/src/pages/Login.vue

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<ff-layout-box class="ff-login">
3-
<div v-if="!pending" data-form="login">
3+
<div v-if="!appLoader" data-form="login">
44
<ff-loading v-if="loggingIn" message="Logging in..." color="white" />
55
<template v-else-if="!mfaRequired">
66
<label>Username / E-Mail</label>
@@ -86,16 +86,20 @@
8686
</template>
8787

8888
<script>
89+
import { mapState } from 'pinia'
8990
import { GoogleLogin } from 'vue3-google-login'
9091
91-
import { mapState } from 'vuex'
92+
import { mapState as mapVuexState } from 'vuex'
9293
9394
import SSOApi from '../api/sso.js'
9495
import Logo from '../components/Logo.vue'
9596
import SpinnerIcon from '../components/icons/Spinner.js'
9697
9798
import FFLayoutBox from '../layouts/Box.vue'
9899
100+
import { useAccountAuthStore } from '@/stores/account-auth.js'
101+
import { useUxLoadingStore } from '@/stores/ux-loading.js'
102+
99103
export default {
100104
name: 'LoginPage',
101105
components: {
@@ -124,7 +128,9 @@ export default {
124128
}
125129
},
126130
computed: {
127-
...mapState('account', ['settings', 'pending', 'loginError', 'redirectUrlAfterLogin']),
131+
...mapVuexState('account', ['settings']),
132+
...mapState(useAccountAuthStore, ['loginError', 'redirectUrlAfterLogin']),
133+
...mapState(useUxLoadingStore, ['appLoader']),
128134
tokenInvalid () {
129135
return this.mfaRequired && !/^\d{6}$/.test(this.input.token)
130136
},

0 commit comments

Comments
 (0)