Vue Auth / Recipes / Manually Authenticating and Setting a User

There may be cases where a manual approach is required.

Typically we may just want to update the user rather than performing a fetch to refresh the data.

Updating User

To then set it manually call user with data.

this.$auth
    .user({
        id: 1,
        email: '[email protected]',
        full_name: 'Rob Nova'
    });

Disable Auto Fech

If the auto fetch needs to be disabled in favor of a manual approach.

First make sure to disable fetch in the plugin config.

Vue.use(auth, {
    ...    

    fetchData: {
        enabled: false
    }
});

Full Manual

A full manual approach might look like something below.

Here we don't even call any login method so nothing needs to be disabled.

this.$auth.token(null, 'TOKEN-CODE', false);

this.$auth.user({
    id: 1,
    first_name: 'Manual',
    email: '[email protected]',
    type: 'user',
});

if (this.form.remember) {
    this.$auth.remember(JSON.stringify({
        name: this.$auth.user().first_name
    }));
}
else {
    this.$auth.unremember();
}

this.$router.push({
    name: 'user-landing'
});