@miebale/vue-auth-core
v0.1.0
Published
Reusable Vue 3 auth core utilities extracted from business-linkage-vue.
Maintainers
Readme
@miebale/vue-auth-core
Reusable Vue 3 auth primitives:
createAuthPlugincreateAuthGuarduseAuth- storage adapters for
localStorage,sessionStorage, and memory
Install
npm install @miebale123/vue-auth-core
npm install @miebale/vue-auth-coreUsage
import {
createAuthGuard,
createAuthPlugin,
createLocalStorageAdapter,
} from 'business-linkage-vue-auth-core'
} from '@miebale/vue-auth-core'
const auth = createAuthPlugin({
api: {
login: async (payload) => {
const response = await api.login(payload)
return { token: response.token }
},
me: async (token) => api.me(token),
logout: async (token) => api.logout(token),
},
routes: {
login: '/login',
home: '/dashboard',
unauthorized: '/unauthorized',
},
storage: createLocalStorageAdapter('auth-token'),
isUnauthorizedError: (error) =>
error instanceof Error && error.message === 'Unauthorized',
})
app.use(auth)
router.beforeEach(createAuthGuard(auth))
await auth.bootstrap()