如何在 Laravel Passport 中获取用户详细信息

abu*_*abu 0 vuejs2 laravel-passport laravel-5.6

我正在使用 Laravel 5.6 和 vue.js2 开发应用程序。我使用 Laravel Passport 作为 API 进行用户身份验证。我routeapi.phpLaravel 中对此一无所知。我在vue.js.

methods: {
        login() {
            var data = {
                client_id: 2,
                client_secret: 'ispGH4SmkEeV4i5Tz9NoI0RSzid5mciG5ecw011f',
                grant_type: 'password',
                username: this.email,
                password: this.password
            }
            this.$http.post('http://127.0.0.1:8000/oauth/token',data)
                .then( response => {
                    this.$auth.setToken(response.body.access_token, response.body.expires_in + Date.now())                        
                    this.$router.push('dashboard')
            })
        }
    }
Run Code Online (Sandbox Code Playgroud)

现在我想获取认证的用户的细节,如userNameemail等。

小智 5

在您将令牌设置为标头请求(我假设您在 中这样做this.$auth.setToken)后,发出一个 get 请求以进行/api/user路由:

this.$http.get('/user').then(res => {
     this.user = res.data;
}).catch(err => console.log(err));
Run Code Online (Sandbox Code Playgroud)

(该路由默认存在于 routes/api.php 文件中)。