mirror of
https://gitlab.com/bramw/baserow.git
synced 2025-04-14 09:08:32 +00:00
Fix re-login process with the auth form
This commit is contained in:
parent
41743f7b02
commit
a23da02755
5 changed files with 76 additions and 66 deletions
changelog/entries/unreleased/bug
enterprise/web-frontend/modules/baserow_enterprise/builder/components/elements
web-frontend/modules/builder
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"type": "bug",
|
||||||
|
"message": "Using login form if you are already logged doesn't require to click twice on the button anymore",
|
||||||
|
"issue_number": 2476,
|
||||||
|
"bullet_points": [],
|
||||||
|
"created_at": "2024-03-28"
|
||||||
|
}
|
|
@ -131,55 +131,55 @@ export default {
|
||||||
}),
|
}),
|
||||||
async onLogin(event) {
|
async onLogin(event) {
|
||||||
if (this.isAuthenticated) {
|
if (this.isAuthenticated) {
|
||||||
this.$store.dispatch('userSourceUser/logoff')
|
await this.$store.dispatch('userSourceUser/logoff')
|
||||||
} else {
|
|
||||||
this.$v.$touch()
|
|
||||||
if (this.$v.$invalid) {
|
|
||||||
this.focusOnFirstError()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
this.loading = true
|
|
||||||
this.hideError()
|
|
||||||
try {
|
|
||||||
await this.$store.dispatch('userSourceUser/authenticate', {
|
|
||||||
userSource: this.selectedUserSource,
|
|
||||||
credentials: {
|
|
||||||
email: this.values.email,
|
|
||||||
password: this.values.password,
|
|
||||||
},
|
|
||||||
setCookie: this.mode === 'public',
|
|
||||||
})
|
|
||||||
this.values.password = ''
|
|
||||||
this.values.email = ''
|
|
||||||
this.$v.$reset()
|
|
||||||
this.fireAfterLoginEvent()
|
|
||||||
} catch (error) {
|
|
||||||
if (error.handler) {
|
|
||||||
const response = error.handler.response
|
|
||||||
if (response && response.status === 401) {
|
|
||||||
this.values.password = ''
|
|
||||||
this.$v.$reset()
|
|
||||||
this.$v.$touch()
|
|
||||||
this.$refs.passwordRef.focus()
|
|
||||||
|
|
||||||
if (response.data?.error === 'ERROR_INVALID_CREDENTIALS') {
|
|
||||||
this.showError(
|
|
||||||
this.$t('error.incorrectCredentialTitle'),
|
|
||||||
this.$t('error.incorrectCredentialMessage')
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const message = error.handler.getMessage('login')
|
|
||||||
this.showError(message)
|
|
||||||
}
|
|
||||||
|
|
||||||
error.handler.handled()
|
|
||||||
} else {
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.loading = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.$v.$touch()
|
||||||
|
if (this.$v.$invalid) {
|
||||||
|
this.focusOnFirstError()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.loading = true
|
||||||
|
this.hideError()
|
||||||
|
try {
|
||||||
|
await this.$store.dispatch('userSourceUser/authenticate', {
|
||||||
|
userSource: this.selectedUserSource,
|
||||||
|
credentials: {
|
||||||
|
email: this.values.email,
|
||||||
|
password: this.values.password,
|
||||||
|
},
|
||||||
|
setCookie: this.mode === 'public',
|
||||||
|
})
|
||||||
|
this.values.password = ''
|
||||||
|
this.values.email = ''
|
||||||
|
this.$v.$reset()
|
||||||
|
this.fireAfterLoginEvent()
|
||||||
|
} catch (error) {
|
||||||
|
if (error.handler) {
|
||||||
|
const response = error.handler.response
|
||||||
|
if (response && response.status === 401) {
|
||||||
|
this.values.password = ''
|
||||||
|
this.$v.$reset()
|
||||||
|
this.$v.$touch()
|
||||||
|
this.$refs.passwordRef.focus()
|
||||||
|
|
||||||
|
if (response.data?.error === 'ERROR_INVALID_CREDENTIALS') {
|
||||||
|
this.showError(
|
||||||
|
this.$t('error.incorrectCredentialTitle'),
|
||||||
|
this.$t('error.incorrectCredentialMessage')
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const message = error.handler.getMessage('login')
|
||||||
|
this.showError(message)
|
||||||
|
}
|
||||||
|
|
||||||
|
error.handler.handled()
|
||||||
|
} else {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.loading = false
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
validations: {
|
validations: {
|
||||||
|
|
|
@ -37,11 +37,6 @@ export default {
|
||||||
required: false,
|
required: false,
|
||||||
default: null,
|
default: null,
|
||||||
},
|
},
|
||||||
isInError: {
|
|
||||||
type: Boolean,
|
|
||||||
required: false,
|
|
||||||
default: null,
|
|
||||||
},
|
|
||||||
label: {
|
label: {
|
||||||
type: String,
|
type: String,
|
||||||
required: false,
|
required: false,
|
||||||
|
@ -70,7 +65,7 @@ export default {
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
hasError() {
|
hasError() {
|
||||||
return this.isInError !== null ? this.isInError : Boolean(this.error)
|
return Boolean(this.errorMessage)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,7 @@
|
||||||
<div>
|
<div>
|
||||||
<ABFormGroup
|
<ABFormGroup
|
||||||
:label="resolvedLabel"
|
:label="resolvedLabel"
|
||||||
:is-in-error="displayFormDataError"
|
:error-message="errorMessage"
|
||||||
:error-message="errorForValidationType"
|
|
||||||
:autocomplete="isEditMode ? 'off' : ''"
|
:autocomplete="isEditMode ? 'off' : ''"
|
||||||
:required="element.required"
|
:required="element.required"
|
||||||
>
|
>
|
||||||
|
@ -40,16 +39,6 @@ export default {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
errorForValidationType() {
|
|
||||||
switch (this.element.validation_type) {
|
|
||||||
case 'integer':
|
|
||||||
return this.$t('error.invalidNumber')
|
|
||||||
case 'email':
|
|
||||||
return this.$t('error.invalidEmail')
|
|
||||||
default:
|
|
||||||
return this.$t('error.requiredField')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
resolvedDefaultValue() {
|
resolvedDefaultValue() {
|
||||||
return this.resolveFormula(this.element.default_value)
|
return this.resolveFormula(this.element.default_value)
|
||||||
},
|
},
|
||||||
|
@ -68,5 +57,17 @@ export default {
|
||||||
immediate: true,
|
immediate: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
methods: {
|
||||||
|
getErrorMessage() {
|
||||||
|
switch (this.element.validation_type) {
|
||||||
|
case 'integer':
|
||||||
|
return this.$t('error.invalidNumber')
|
||||||
|
case 'email':
|
||||||
|
return this.$t('error.invalidEmail')
|
||||||
|
default:
|
||||||
|
return this.$t('error.requiredField')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -25,6 +25,9 @@ export default {
|
||||||
!this.isEditMode
|
!this.isEditMode
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
errorMessage() {
|
||||||
|
return this.displayFormDataError ? this.getErrorMessage() : ''
|
||||||
|
},
|
||||||
formElementTouched() {
|
formElementTouched() {
|
||||||
return this.$store.getters['formData/getElementTouched'](
|
return this.$store.getters['formData/getElementTouched'](
|
||||||
this.page,
|
this.page,
|
||||||
|
@ -81,6 +84,10 @@ export default {
|
||||||
elementId: this.element.id,
|
elementId: this.element.id,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
/** Override this method to display the right error message */
|
||||||
|
getErrorMessage() {
|
||||||
|
return ''
|
||||||
|
},
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue