首页 > 解决方案 > 使用Vue Js和Laravel提交身份验证后如何修复localhost:8000提示登录

问题描述

登录后我的身份验证出现问题,提示 localhost:8000 登录或登录,这是我第一次遇到这种情况,我不知道这叫什么,我没有找到任何参考。目前我在后端使用 laravel,前端使用 vue js。所以这个项目是由老开发者创建的。所以现在我需要修改那里项目的一些模块,但是我在系统上登录显示这个提示。请注意,该项目当前正在运行,并且在我登录时没有错误并提示登录。

这是我登录后显示的提示标志。

配置:

  1. Laravel 护照
  2. Vuex 状态管理
  3. Vue Js

提示信息

方法:

methods:{
        authenticate(){
            this.login_alert = false
            this.$validator.validateAll().then((result)=>{
                if(result){
                    const self = this;
                    const authUser = {}
                    try{
                        const data = {
                            username: this.email,
                            password: this.password,
                            remember: this.remember_me,
                            client_id: '2',
                            client_secret: 'just secret only',
                            grant_type : 'password',
                            scope : ''
                        }
                        this.$store.dispatch('AUTH_REQUEST',data)
                            .then(response=>{
                                authUser.access_token = response.access_token
                                authUser.refresh_token = response.refresh_token
                                authUser.expires_in = response.expires_in
                                window.localStorage.setItem('project_token',JSON.stringify(authUser))

                                /*LOGIN*/
                                this.login_alert = false
                                this.loading = false

                                window.location.reload()
                            })
                            .catch(error=>{
                                this.login_alert = true
                                window.localStorage.removeItem('project_token')
                                this.loading = false
                            })
                    }catch(err){
                        console.log(err);
                    }
                }
            })
        
        }
    },

授权请求:

AUTH_REQUEST:({commit,dispatch},obj)=>{
    return new Promise((resolve,reject) => {
        axios({
                url: '/oauth/token',
                data: obj,
                method:'post',
                config:'JSON'
            })
            .then(response=>{
                if(response.status == 200){
                    resolve(response.data);
                }
            })
            .catch(error=>{
                reject(error);
                localStorage.removeItem('project_token');
                commit('AUTH_ERROR',error);
            })
    
    })
},

希望有人可以帮助我解决这个问题。谢谢你。

标签: laravelvue.jsvuex

解决方案


推荐阅读