Skip to content

Commit

Permalink
Merge pull request #2780 from patzick/bugfix/multiple-redirections-on…
Browse files Browse the repository at this point in the history
…-my-account-refresh

Bugfix/multiple redirections on my account refresh
  • Loading branch information
pkarw committed Apr 24, 2019
2 parents 98d85e6 + 327b4e6 commit debe392
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 24 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- ESlint throwing errors about undefined jest globals in tests - @lukeromanowicz (#2702)
- Fixed changing the country when entering shipping address in checkout not updating shipping costs - @revlis-x (#2691)
- Infinite loop on multistore page after reload - @patzick (#2713)
- Refreshing MyAccount page on multistore - @patzick (#2780)
- "Toggle password visible" button in password fields works the right way - @lromanowicz (#2772)

## [1.9.0-rc.2] - 2019.04.10
Expand Down
4 changes: 2 additions & 2 deletions core/modules/user/hooks/afterRegistration.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Vue from 'vue'
import * as types from './../store/mutation-types'

export function afterRegistration({ Vue, config, store, isServer }){
export async function afterRegistration({ Vue, config, store, isServer }){
if (!isServer) {
store.dispatch('user/startSession')
await store.dispatch('user/startSession')

Vue.prototype.$bus.$on('user-before-logout', () => {
store.dispatch('user/logout', { silent: false })
Expand Down
15 changes: 4 additions & 11 deletions core/modules/user/router/beforeEach.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { Route } from 'vue-router'
import rootStore from '@vue-storefront/core/store'
import i18n from '@vue-storefront/i18n'
import { isServer } from '@vue-storefront/core/helpers'
import { router } from '@vue-storefront/core/app'

export function beforeEach(to: Route, from: Route, next) {
export async function beforeEach(to: Route, from: Route, next) {
const requiresAuth = to.matched.some(route => route.meta.requiresAuth)
if (requiresAuth) {
if (isServer) {
next('/')
next()
} else {
await rootStore.dispatch('user/startSession')
if (!rootStore.getters['user/isLoggedIn']) {
next('/')
rootStore.dispatch('notification/spawnNotification', {
Expand All @@ -18,14 +18,7 @@ export function beforeEach(to: Route, from: Route, next) {
action1: { label: i18n.t('OK') }
})
} else {
if (!from.name) {
next('/')
setTimeout(()=> {
router.push(to.path)
}, 0)
} else {
next()
}
next()
}
}
} else {
Expand Down
13 changes: 7 additions & 6 deletions core/modules/user/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import UserState from '../types/UserState'
import { Logger } from '@vue-storefront/core/lib/logger'
import { TaskQueue } from '@vue-storefront/core/lib/sync'
import { UserProfile } from '../types/UserProfile'
import { currentStoreView } from '@vue-storefront/core/lib/multistore'
import { isServer } from '@vue-storefront/core/helpers'
// import router from '@vue-storefront/core/router'

const actions: ActionTree<UserState, RootState> = {
startSession (context) {
const storeView = currentStoreView()
const dbNamePrefix = storeView.storeCode ? storeView.storeCode + '-' : ''
const user = localStorage.getItem(`${dbNamePrefix}shop/user/current-user`);
async startSession (context) {
if (isServer || context.getters.isLocalDataLoaded) return
context.commit(types.USER_LOCAL_DATA_LOADED, true)

const user = localStorage.getItem(`shop/user/current-user`);
if (user) {
context.commit(types.USER_INFO_LOADED, JSON.parse(user))
}
Expand Down Expand Up @@ -171,7 +172,7 @@ const actions: ActionTree<UserState, RootState> = {
/**
* Load current user profile
*/
me (context, { refresh = true, useCache = true }) {
me (context, { refresh = true, useCache = true } = {}) {
return new Promise((resolve, reject) => {
if (!context.state.token) {
Logger.warn('No User token, user unauthorized', 'user')()
Expand Down
1 change: 1 addition & 0 deletions core/modules/user/store/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const getters: GetterTree<UserState, RootState> = {
isLoggedIn (state) {
return state.current !== null
},
isLocalDataLoaded: state => state.local_data_loaded,
getUserToken (state) {
return state.token
}
Expand Down
3 changes: 2 additions & 1 deletion core/modules/user/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export const module: Module<UserState, RootState> = {
current: null,
current_storecode: '',
session_started: new Date(),
orders_history: null
orders_history: null,
local_data_loaded: false
},
getters,
actions,
Expand Down
3 changes: 2 additions & 1 deletion core/modules/user/store/mutation-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export const USER_START_SESSION = SN_USER + '/START_SESSION'
export const USER_END_SESSION = SN_USER + '/END_SESSION'
export const USER_UPDATE_PREFERENCES = SN_USER + '/UPDATE_PREFERENCES'
export const USER_GROUP_TOKEN_CHANGED = SN_USER + '/GROUP_TOKEN_CHANGED'
export const USER_GROUP_CHANGED = SN_USER + 'GROUP_ID_CHANGED'
export const USER_GROUP_CHANGED = SN_USER + '/GROUP_ID_CHANGED'
export const USER_LOCAL_DATA_LOADED = SN_USER + '/LOCAL_DATA_LOADED'
3 changes: 3 additions & 0 deletions core/modules/user/store/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const mutations: MutationTree<UserState> = {
state.token = ''
state.current = null
state.session_started = null
},
[types.USER_LOCAL_DATA_LOADED] (state, readed = false) {
state.local_data_loaded = readed
}
}

Expand Down
3 changes: 2 additions & 1 deletion core/modules/user/types/UserState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export default interface UserState {
} | null,
current_storecode: string,
session_started: Date,
orders_history: any
orders_history: any,
local_data_loaded: boolean
}
8 changes: 6 additions & 2 deletions src/themes/default/pages/MyAccount.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
</nav>
</div>
<div class="col-md-9">
<component :is="this.$props.activeBlock" />
<no-ssr>
<component :is="this.$props.activeBlock" />
</no-ssr>
</div>
</div>
</div>
Expand All @@ -40,6 +42,7 @@ import MyNewsletter from '../components/core/blocks/MyAccount/MyNewsletter'
import MyOrders from '../components/core/blocks/MyAccount/MyOrders'
import MyOrder from '../components/core/blocks/MyAccount/MyOrder'
import MyRecentlyViewed from '../components/core/blocks/MyAccount/MyRecentlyViewed'
import NoSSR from 'vue-no-ssr'
export default {
data () {
Expand All @@ -62,7 +65,8 @@ export default {
MyNewsletter,
MyOrders,
MyOrder,
MyRecentlyViewed
MyRecentlyViewed,
'no-ssr': NoSSR
},
mixins: [MyAccount],
methods: {
Expand Down

0 comments on commit debe392

Please sign in to comment.