feat: keep errorMessage local (#865)

Co-authored-by: Dominik Pschenitschni <mail@celement.de>
Co-authored-by: kolaente <k@knt.li>
Co-authored-by: konrad <k@knt.li>
Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/865
Co-authored-by: dpschen <dpschen@noreply.kolaente.de>
Co-committed-by: dpschen <dpschen@noreply.kolaente.de>
This commit is contained in:
dpschen 2021-10-17 19:38:30 +00:00 committed by konrad
parent 1fc857d9a2
commit 0a1d0084e2
6 changed files with 31 additions and 41 deletions

View file

@ -2,7 +2,6 @@ import {createStore} from 'vuex'
import { import {
BACKGROUND, BACKGROUND,
CURRENT_LIST, CURRENT_LIST,
ERROR_MESSAGE,
HAS_TASKS, HAS_TASKS,
KEYBOARD_SHORTCUTS_ACTIVE, KEYBOARD_SHORTCUTS_ACTIVE,
LOADING, LOADING,
@ -36,7 +35,6 @@ export const store = createStore({
state: { state: {
loading: false, loading: false,
loadingModule: null, loadingModule: null,
errorMessage: '',
online: true, online: true,
// This is used to highlight the current list in menu for all list related views // This is used to highlight the current list in menu for all list related views
currentList: {id: 0}, currentList: {id: 0},
@ -53,9 +51,6 @@ export const store = createStore({
[LOADING_MODULE](state, module) { [LOADING_MODULE](state, module) {
state.loadingModule = module state.loadingModule = module
}, },
[ERROR_MESSAGE](state, error) {
state.errorMessage = error
},
[ONLINE](state, online) { [ONLINE](state, online) {
if (import.meta.env.VITE_IS_ONLINE) { if (import.meta.env.VITE_IS_ONLINE) {
console.log('Setting fake online state', import.meta.env.VITE_IS_ONLINE) console.log('Setting fake online state', import.meta.env.VITE_IS_ONLINE)

View file

@ -1,5 +1,5 @@
import {HTTPFactory} from '@/http-common' import {HTTPFactory} from '@/http-common'
import {ERROR_MESSAGE, LOADING} from '../mutation-types' import {LOADING} from '../mutation-types'
import UserModel from '../../models/user' import UserModel from '../../models/user'
import {getToken, refreshToken, removeToken, saveToken} from '@/helpers/auth' import {getToken, refreshToken, removeToken, saveToken} from '@/helpers/auth'
@ -128,8 +128,8 @@ export default {
}) })
return ctx.dispatch('login', credentials) return ctx.dispatch('login', credentials)
} catch(e) { } catch(e) {
if (e.response && e.response.data && e.response.data.message) { if (e.response?.data?.message) {
ctx.commit(ERROR_MESSAGE, e.response.data.message, {root: true}) throw e.response.data
} }
throw e throw e

View file

@ -1,6 +1,5 @@
export const LOADING = 'loading' export const LOADING = 'loading'
export const LOADING_MODULE = 'loadingModule' export const LOADING_MODULE = 'loadingModule'
export const ERROR_MESSAGE = 'errorMessage'
export const ONLINE = 'online' export const ONLINE = 'online'
export const CURRENT_LIST = 'currentList' export const CURRENT_LIST = 'currentList'
export const HAS_TASKS = 'hasTasks' export const HAS_TASKS = 'hasTasks'

View file

@ -105,7 +105,7 @@
import {mapState} from 'vuex' import {mapState} from 'vuex'
import {HTTPFactory} from '@/http-common' import {HTTPFactory} from '@/http-common'
import {ERROR_MESSAGE, LOADING} from '@/store/mutation-types' import {LOADING} from '@/store/mutation-types'
import legal from '../../components/misc/legal' import legal from '../../components/misc/legal'
import ApiConfig from '@/components/misc/api-config.vue' import ApiConfig from '@/components/misc/api-config.vue'
import {getErrorText} from '@/message' import {getErrorText} from '@/message'
@ -121,6 +121,7 @@ export default {
return { return {
confirmedEmailSuccess: false, confirmedEmailSuccess: false,
hasApiUrl: false, hasApiUrl: false,
errorMessage: '',
} }
}, },
beforeMount() { beforeMount() {
@ -138,7 +139,7 @@ export default {
}) })
.catch(e => { .catch(e => {
cancel() cancel()
this.$store.commit(ERROR_MESSAGE, e.response.data.message) this.errorMessage = e.response.data.message
}) })
} }
@ -170,7 +171,6 @@ export default {
...mapState({ ...mapState({
registrationEnabled: state => state.config.registrationEnabled, registrationEnabled: state => state.config.registrationEnabled,
loading: LOADING, loading: LOADING,
errorMessage: ERROR_MESSAGE,
needsTotpPasscode: state => state.auth.needsTotpPasscode, needsTotpPasscode: state => state.auth.needsTotpPasscode,
authenticated: state => state.auth.authenticated, authenticated: state => state.auth.authenticated,
localAuthEnabled: state => state.config.auth.local.enabled, localAuthEnabled: state => state.config.auth.local.enabled,
@ -189,7 +189,7 @@ export default {
}, },
async submit() { async submit() {
this.$store.commit(ERROR_MESSAGE, '') this.errorMessage = ''
// Some browsers prevent Vue bindings from working with autofilled values. // Some browsers prevent Vue bindings from working with autofilled values.
// To work around this, we're manually getting the values here instead of relying on vue bindings. // To work around this, we're manually getting the values here instead of relying on vue bindings.
// For more info, see https://kolaente.dev/vikunja/frontend/issues/78 // For more info, see https://kolaente.dev/vikunja/frontend/issues/78
@ -211,12 +211,7 @@ export default {
} }
const err = getErrorText(e) const err = getErrorText(e)
if (typeof err[1] !== 'undefined') { this.errorMessage = typeof err[1] !== 'undefined' ? err[1] : err[0]
this.$store.commit(ERROR_MESSAGE, err[1])
return
}
this.$store.commit(ERROR_MESSAGE, err[0])
} }
}, },

View file

@ -12,14 +12,18 @@
<script> <script>
import {mapState} from 'vuex' import {mapState} from 'vuex'
import {ERROR_MESSAGE, LOADING} from '@/store/mutation-types' import {LOADING} from '@/store/mutation-types'
import {getErrorText} from '@/message' import {getErrorText} from '@/message'
import {clearLastVisited, getLastVisited} from '../../helpers/saveLastVisited' import {clearLastVisited, getLastVisited} from '../../helpers/saveLastVisited'
export default { export default {
name: 'Auth', name: 'Auth',
data() {
return {
errorMessage: '',
}
},
computed: mapState({ computed: mapState({
errorMessage: ERROR_MESSAGE,
loading: LOADING, loading: LOADING,
}), }),
mounted() { mounted() {
@ -40,25 +44,23 @@ export default {
} }
localStorage.setItem('authenticating', true) localStorage.setItem('authenticating', true)
this.errorMessage = ''
if (typeof this.$route.query.error !== 'undefined') { if (typeof this.$route.query.error !== 'undefined') {
let error = this.$t('user.auth.openIdGeneralError')
if (typeof this.$route.query.message !== 'undefined') {
error = this.$route.query.message
}
localStorage.removeItem('authenticating') localStorage.removeItem('authenticating')
this.$store.commit(ERROR_MESSAGE, error) this.errorMessage = typeof this.$route.query.message !== 'undefined'
? this.$route.query.message
: this.$t('user.auth.openIdGeneralError')
return return
} }
const state = localStorage.getItem('state') const state = localStorage.getItem('state')
if (typeof this.$route.query.state === 'undefined' || this.$route.query.state !== state) { if (typeof this.$route.query.state === 'undefined' || this.$route.query.state !== state) {
localStorage.removeItem('authenticating') localStorage.removeItem('authenticating')
this.$store.commit(ERROR_MESSAGE, this.$t('user.auth.openIdStateError')) this.errorMessage = this.$t('user.auth.openIdStateError')
return return
} }
this.$store.commit(ERROR_MESSAGE, '')
try { try {
await this.$store.dispatch('auth/openIdAuth', { await this.$store.dispatch('auth/openIdAuth', {
provider: this.$route.params.provider, provider: this.$route.params.provider,
@ -76,12 +78,7 @@ export default {
} }
} catch(e) { } catch(e) {
const err = getErrorText(e) const err = getErrorText(e)
if (typeof err[1] !== 'undefined') { this.errorMessage = typeof err[1] !== 'undefined' ? err[1] : err[0]
this.$store.commit(ERROR_MESSAGE, err[1])
return
}
this.$store.commit(ERROR_MESSAGE, err[0])
} finally { } finally {
localStorage.removeItem('authenticating') localStorage.removeItem('authenticating')
} }

View file

@ -98,7 +98,7 @@
<script> <script>
import router from '../../router' import router from '../../router'
import {mapState} from 'vuex' import {mapState} from 'vuex'
import {ERROR_MESSAGE, LOADING} from '@/store/mutation-types' import {LOADING} from '@/store/mutation-types'
import Legal from '../../components/misc/legal' import Legal from '../../components/misc/legal'
export default { export default {
@ -113,6 +113,7 @@ export default {
password: '', password: '',
password2: '', password2: '',
}, },
errorMessage: '',
} }
}, },
beforeMount() { beforeMount() {
@ -127,15 +128,14 @@ export default {
computed: mapState({ computed: mapState({
authenticated: state => state.auth.authenticated, authenticated: state => state.auth.authenticated,
loading: LOADING, loading: LOADING,
errorMessage: ERROR_MESSAGE,
}), }),
methods: { methods: {
submit() { async submit() {
this.$store.commit(LOADING, true) this.$store.commit(LOADING, true)
this.$store.commit(ERROR_MESSAGE, '') this.errorMessage = ''
if (this.credentials.password2 !== this.credentials.password) { if (this.credentials.password2 !== this.credentials.password) {
this.$store.commit(ERROR_MESSAGE, this.$t('user.auth.passwordsDontMatch')) this.errorMessage = this.$t('user.auth.passwordsDontMatch')
this.$store.commit(LOADING, false) this.$store.commit(LOADING, false)
return return
} }
@ -146,7 +146,11 @@ export default {
password: this.credentials.password, password: this.credentials.password,
} }
this.$store.dispatch('auth/register', credentials) try {
await this.$store.dispatch('auth/register', credentials)
} catch(e) {
this.errorMessage = e.message
}
}, },
}, },
} }