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.