User authentication. Page freezes

my-doctors-pacients
0
my-doctors-pacients
commented 3 months ago

Hello everybody. I do authentication on nakst + django. When you try to log in, the page freezes. What could be the problem?
login.vue
<template>
<el-card shadow="always" :style="{ width: '500px' }">
<el-form :model="userData" :rules="rules" ref="form" @submit.native.prevent="logInUser" >

Login

        <el-form-item label="Email" prop="email">
            <el-input v-model.trim="userData.email" />
        </el-form-item>

        <div class="mb2">
            <el-form-item label="Пароль" prop="password">
                <el-input
                    v-model.trim="userData.password"
                    type="password"
                />
            </el-form-item>
        </div>

        <el-form-item>
            <el-button
                type="primary"
                native-type="submit"
                round
                :loading="loading"
                 @click="logInUser(userData)"
            >
                Войти
            </el-button>
        </el-form-item>
    </el-form>
</el-card>

</template>

<script> export default { layout: "empty", middleware: ['admin-auth'], data() { return { loading: false, userData: { email: '', password: '', }, rules: { email: [ { required: true, message: "Введите email", trigger: "blur", }, ], password: [ { required: true, message: "Введите пароль", trigger: "blur", }, { min: 6, message: "Пароль должен быть не менее 6 символов", trigger: "blur", }, ], }, }; }, methods: { async logInUser(userData) { this.$refs.form.validate(async (valid) => { if (valid) { this.loading = true; try { await this.$auth.loginWith('local', { data: userData, }) this.$message('Login!!!!!!!!!!!!!!') this.$router.push("/admin/") console.log('notification successful') } catch (error) { this.$message({ message: 'Warning, this is a warning message.', type: 'warning' }); console.log('notification unsuccessful') this.$router.push("/login"), this.loading = false; } console.log(this.$auth.user) } }); }, }, }; </script>

middleware/admin-auth.js
export default function ({ store, redirect }) {
if (store.state.auth.loggedIn) {
return redirect('/admin/')
}
if (!store.state.auth.loggedIn) {
return redirect('/login')
}
}

store/index.js
export const getters = {
isAuthenticated(state) {
return state.auth.loggedIn
},

loggedInUser(state) {
    return state.auth.user
}

}

0
Informations
QuestionUnresolved
#c53 - Created 3 months ago