0

I'm rebuilding legacy Nuxt 2, Vue 2, Vuex code using Nuxt 3, Vue 3 and Pinia. I'm using @sidebase/nuxt-auth 0.6.0 (beta) "local" provider for the user authorisation.

I am able to login/logout the user etc. My problem is with getting access to the user data, I want to store this in a useUserStore (Pinia), so that I'm able to process the user permissions inside my store and provide getters for these permissions.

I have tried the following:

This is my Pinia Store:

const { signIn, data } = useAuth();

export const useUserStore = defineStore("user", () => {
  const user = ref({});

  async function loginUser(credentials: any) {
    try {
      await signIn({
        email_address: credentials.email_address,
        password: credentials.password,
      });
      console.log(data);
    } catch (e) {}
  }
  return { user, loginUser };
});

When I console log the useAuth Data, nothing gets logged..

I have also tried doing:

const { signIn, data } = useAuth();

export const useUserStore = defineStore("user", () => {
  const user = ref({});

  function loginUser(credentials: any) {
    try {
      signIn({
        email_address: credentials.email_address,
        password: credentials.password,
      }).then((response) => {
        console.log(response);
      });
    } catch (e) {}
  }
  return { user, loginUser };
});

but that also doesn't work.

How can I set my user ref with the useAuth data? My endgoal is to have the user info available in my Pinia Store.

Jeroen
  • 1
  • 2

1 Answers1

1

You wont see output from your console logs if signIn function is producing an error, the code will escape before executing console.log in both your examples, and you have no visibility of your errors because you have basically silenced them by doing catch (e) {}.

First I would start with modifying catch to catch (e) { console.dir(e) } and ensure its not erroring out before trying to debug this any further.

Marc
  • 5,109
  • 2
  • 32
  • 41