Skip to content

Correctly use vue-auth #1

@N1K1TAS95

Description

@N1K1TAS95

Hi there!
I'm trying to use your plugin to implement JWT authentication and consume REST APIs served by Django.
First of all I'm a rookie in JavaScript and in Vue...

I'm using Vue 3.2.13

my main.js file:

import { createApp } from 'vue'
import App from '@/App.vue'
import router from '@/router'
import store from '@/store'
import vuetify from '@/plugins/vuetify'
import { loadFonts } from '@/plugins/webfontloader'
import axios from 'axios'
import VueAxios from 'vue-axios'
import Auth from '@gravitano/vue-auth'

loadFonts()

const app = createApp(App)

app.use(router)
app.use(store)
app.use(vuetify)
app.use(VueAxios, axios)

app.use(Auth)

app.mount('#app')

I'm trying to access the global variable $auth in my Vue components, but it's always undefined. In template part through {{ $auth.user.name }} or in script through this.$auth.user.name.

I also get an error in browser inspect console [Vue warn]: A plugin must either be a function or an object with an "install" function. and guess it's referred to app.use(Auth).

Could you help me?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions