#✅ Vue3 frontend directus authentification error

23 messages · Page 1 of 1 (latest)

lusty glacier
#

Hello

I have a very strange error that I can't seem to find a solution for. Have built a vue 3 application that uses directus to authenticate.

I have two different users and try to log in and log out even though I logged out the first user, I get his information in response when I log in as user 2?

I use the directus SDK..

Here is the login function:

async login({ email, password }) {
  try {
    await directus.auth.login({
      email,
      password,
    })

    // If login was successful, fetch the users data
    const user = await directus.users.me.read({
      fields: ['id', 'email', 'first_name', 'last_name', 'avatar', 'role'],
    })

    console.log(user)

    // Update the auth store with the user data
    this.loggedIn = true
    this.user = user

    // Redirect to home page
    this.router.push(this.returnUrl || '/')
  } catch (e) {
    console.error(e.message)
    throw new Error('Fel användarnamn eller lösenord. Prova igen!')
  }
},

Logout function:

async logout() {
  try {
    await directus.auth.logout()

    this.$reset()

    // Remove rest in localstorage
    localStorage.clear()

    this.router.push('/login')
  } catch (e) {
    console.error(e.message)
    throw new Error('Något blev fel vid utloggningen.')
  }
},

I invoking directus by:

import { Directus } from '@directus/sdk'

export const useDirectus = () => {
const directus = new Directus(import.meta.env.VITE_DIRECTUS_URL, { auth: { mode: 'json' } })

return directus
}

chrome stagBOT
#

Thanks for posting! This is a community powered server, so you may or may not get an answer based on available help and expertise. To increase your chances of somebody being able to help you, please make sure your question includes the following:

  • An explanation of exactly what you're trying to achieve.
  • Any and all related code or previous attempts.
  • The exact issue or error you are facing.
  • Any screenshots if applicable.

When you're done with this thread, please close it.

(If you have a support agreement and need help, please contact the core team via email.)

lusty glacier
#

one sec

#

Hi @lusty glacier you are using VueJS 3.0 framework or NuxtJS 3.0 framework?

#

Vue3 3.0

lusty glacier
#

One more question: you are using it from scratch?

#

Could you change it into Nuxt3?

#

@lusty glacier

#

It is not justifiable to change the framework now when a lot of work has already been done on the application

#

Okay, one sec

#

I think you could use oAuth2

#

I implemented Vue3 + oAuth2 + Direcutus for authentication.

#

and use oAuth2 as a middlewear ?

#

Sure

#

Could you hire me?

#

I have developed many web frontend projects using VueJS / Sveltekit / Directus.

#

so I am sure I am able to make a contribution to your work.

chrome stagBOT
#

✅ Vue3 frontend directus authentification error

chrome stagBOT
lusty glacier
#

I turned of the CACHE_ENABLED: 'false' then it all worked again..

sinful goblet