yacinebelghard's avatar

Error in render: "TypeError: Cannot read property 'name' of undefined" laravel passport

Please I need a help . when i want to generate the access Token .i had this error

[Vue warn]: Error in render: "TypeError: Cannot read property 'name' of undefined"

found in

---> at resources\assets\js\components\passport\PersonalAccessTokens.vue and nothing was generating :

I'm using laravel5.4 node -v V8.6.0 npm -v 5.1.0 this is my package.json { "private": true, "scripts": { "dev": "npm run development", "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", "watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", "watch-poll": "npm run watch -- --watch-poll", "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js", "prod": "npm run production", "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js" }, "devDependencies": { "axios": "^0.16.2", "bootstrap-sass": "^3.3.7", "cross-env": "^5.1.4", "jquery": "^3.1.1", "laravel-mix": "^1.0", "lodash": "^4.17.4", "vue": "^2.1.10" } } my app.js

/**

First we will load all of this project's JavaScript dependencies which includes Vue and other libraries. It is a great starting point when building robust, powerful web applications using Vue and Laravel. */ require('./bootstrap');

window.Vue = require('vue');

/**

Next, we will create a fresh Vue application instance and attach it to the page. Then, you may begin adding components to this application or customize the JavaScript scaffolding to fit your unique needs. */ Vue.component('example', require('./components/Example.vue')); Vue.component( 'passport-clients', require('./components/passport/Clients.vue') );

Vue.component( 'passport-authorized-clients', require('./components/passport/AuthorizedClients.vue') );

Vue.component( 'passport-personal-access-tokens', require('./components/passport/PersonalAccessTokens.vue') ); const app = new Vue({ el: '#app' }); thank you .

0 likes
2 replies
bobbybouwmann's avatar

Can you show your vue code? It looks like you try to access a property in a template or method, but the property is not created or is empty!

1 like
yacinebelghard's avatar

this is PersonalAccessTokens.vue

.action-link { cursor: pointer; }
.m-b-none {
    margin-bottom: 0;
}

Personal Access Tokens

                    <a class="action-link" @click="showCreateTokenForm">
                        Create New Token
                    </a>
                </div>
            </div>

            <div class="panel-body">
                <!-- No Tokens Notice -->
                <p class="m-b-none" v-if="tokens.length === 0">
                    You have not created any personal access tokens.
                </p>

                <!-- Personal Access Tokens -->
                <table class="table table-borderless m-b-none" v-if="tokens.length > 0">
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th></th>
                        </tr>
                    </thead>

                    <tbody>
                        <tr v-for="token in tokens">
                            <!-- Client Name -->
                            <td style="vertical-align: middle;">
                                {{ token.name }}
                            </td>

                            <!-- Delete Button -->
                            <td style="vertical-align: middle;">
                                <a class="action-link text-danger" @click="revoke(token)">
                                    Delete
                                </a>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <!-- Create Token Modal -->
    <div class="modal fade" id="modal-create-token" tabindex="-1" role="dialog">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>

                    <h4 class="modal-title">
                        Create Token
                    </h4>
                </div>

                <div class="modal-body">
                    <!-- Form Errors -->
                    <div class="alert alert-danger" v-if="form.errors.length > 0">
                        <p><strong>Whoops!</strong> Something went wrong!</p>
                        <br>
                        <ul>
                            <li v-for="error in form.errors">
                                {{ error }}
                            </li>
                        </ul>
                    </div>

                    <!-- Create Token Form -->
                    <form class="form-horizontal" role="form" @submit.prevent="store">
                        <!-- Name -->
                        <div class="form-group">
                            <label class="col-md-4 control-label">Name</label>

                            <div class="col-md-6">
                                <input id="create-token-name" type="text" class="form-control" name="name" v-model="form.name">
                            </div>
                        </div>

                        <!-- Scopes -->
                        <div class="form-group" v-if="scopes.length > 0">
                            <label class="col-md-4 control-label">Scopes</label>

                            <div class="col-md-6">
                                <div v-for="scope in scopes">
                                    <div class="checkbox">
                                        <label>
                                            <input type="checkbox"
                                                @click="toggleScope(scope.id)"
                                                :checked="scopeIsAssigned(scope.id)">

                                                {{ scope.id }}
                                        </label>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>

                <!-- Modal Actions -->
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>

                    <button type="button" class="btn btn-primary" @click="store">
                        Create
                    </button>
                </div>
            </div>
        </div>
    </div>

    <!-- Access Token Modal -->
    <div class="modal fade" id="modal-access-token" tabindex="-1" role="dialog">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>

                    <h4 class="modal-title">
                        Personal Access Token
                    </h4>
                </div>

                <div class="modal-body">
                    <p>
                        Here is your new personal access token. This is the only time it will be shown so don't lose it!
                        You may now use this token to make API requests.
                    </p>

                    <pre><code>{{ accessToken }}</code></pre>
                </div>

                <!-- Modal Actions -->
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div>
</div>

export default { /* * The component's data. */ data() { return { accessToken: null,
            tokens: [],
            scopes: [],

            form: {
                name: '',
                scopes: [],
                errors: []
            }
        };
    },

    /**
     * Prepare the component (Vue 1.x).
     */
    ready() {
        this.prepareComponent();
    },

    /**
     * Prepare the component (Vue 2.x).
     */
    mounted() {
        this.prepareComponent();
    },

    methods: {
        /**
         * Prepare the component.
         */
        prepareComponent() {
            this.getTokens();
            this.getScopes();

            $('#modal-create-token').on('shown.bs.modal', () => {
                $('#create-token-name').focus();
            });
        },

        /**
         * Get all of the personal access tokens for the user.
         */
        getTokens() {
            axios.get('/oauth/personal-access-tokens')
                    .then(response => {
                        this.tokens = response.data;
                    });
        },

        /**
         * Get all of the available scopes.
         */
        getScopes() {
            axios.get('/oauth/scopes')
                    .then(response => {
                        this.scopes = response.data;
                    });
        },

        /**
         * Show the form for creating new tokens.
         */
        showCreateTokenForm() {
            $('#modal-create-token').modal('show');
        },

        /**
         * Create a new personal access token.
         */
        store() {
            this.accessToken = null;

            this.form.errors = [];

            axios.post('/oauth/personal-access-tokens', this.form)
                    .then(response => {
                        this.form.name = '';
                        this.form.scopes = [];
                        this.form.errors = [];

                        this.tokens.push(response.data.token);

                        this.showAccessToken(response.data.accessToken);
                    })
                    .catch(error => {
                        if (typeof error.response.data === 'object') {
                            this.form.errors = _.flatten(_.toArray(error.response.data));
                        } else {
                            this.form.errors = ['Something went wrong. Please try again.'];
                        }
                    });
        },

        /**
         * Toggle the given scope in the list of assigned scopes.
         */
        toggleScope(scope) {
            if (this.scopeIsAssigned(scope)) {
                this.form.scopes = _.reject(this.form.scopes, s => s == scope);
            } else {
                this.form.scopes.push(scope);
            }
        },

        /**
         * Determine if the given scope has been assigned to the token.
         */
        scopeIsAssigned(scope) {
            return _.indexOf(this.form.scopes, scope) >= 0;
        },

        /**
         * Show the given access token to the user.
         */
        showAccessToken(accessToken) {
            $('#modal-create-token').modal('hide');

            this.accessToken = accessToken;

            $('#modal-access-token').modal('show');
        },

        /**
         * Revoke the given token.
         */
        revoke(token) {
            axios.delete('/oauth/personal-access-tokens/' + token.id)
                    .then(response => {
                        this.getTokens();
                    });
        }
    }
}
it's generated by API PASSPORT (composer require laravel/passport)

Please or to participate in this conversation.