UNPKG

chamesu

Version:

This package contains all packages of the chat application.

77 lines (66 loc) 1.88 kB
/* * Copyright (c) 2022. * Author Peter Placzek (tada5hi) * For the full copyright and license information, * view the LICENSE file that was distributed with this source code. */ import {alphaNum, maxLength, minLength, required} from "vuelidate/lib/validators"; import {mapActions} from "vuex"; const userLoginMixin = { data () { return { loginError: null, loginFormBusy: false, loginForm: { name: '', password: '' } } }, validations: { loginForm: { name: { required, minLength: minLength(5), maxLength: maxLength(100), alphaNum }, password: { required, minLength: minLength(5), maxLength: maxLength(100), } } }, methods: { ...mapActions('auth', [ 'triggerLogin', 'triggerUnsetToken' ]), async doLogin() { if(this.$v.loginForm.$invalid || this.loginFormBusy) { return false; } this.loginFormBusy = true; try { this.triggerUnsetToken(); await this.triggerLogin({ provider: 'local', data: { name: this.loginForm.name, password: this.loginForm.password } }); this.loginFormBusy = false; return true; } catch (e) { this.loginError = e.message; setTimeout(() => { this.loginFormBusy = false; }, 3000) return false; } } } } export default userLoginMixin;