shUser

This is a state management class to manage our logged in user

It uses piniaopen in new window for state management

Importing

import { useUserStore } from '@silahkosgei/sfrontend'

const userStore = useUserStore()

You first import the store class then instantiate it to userStore constant

Using it in component

const { user } = storeToRefs(userStore)

Then you can use it in component template this way

<h5>Welcome {{ user.name }}</h5>

Methods

setAccessToken

This is used to set access token for the logged in user.

userStore.setAccessToken(res.token)

setUser | fetchUser

This gets logged in user from the backend and updates user state

userStore.setUser()

logOut | signOut

This removes current session and logs out user. It basically empties accesstoken from locat storage and makes user state null

userStore.logOut()
Last Updated:
Contributors: silah