@creativecloud/winglet-identity
v0.1.0
Published
Identity client and Vue 3 integration for Winglet applications.
Maintainers
Readme
@creativecloud/winglet-identity
Identity client and Vue 3 integration for Winglet applications.
Install
npm install @creativecloud/winglet-identity @creativecloud/winglet-clientFor Vue integration:
npm install pinia vue-routerCore client
import {
IdentityClient,
localStorageIdentityTokenStorage,
} from '@creativecloud/winglet-identity'
const identity = new IdentityClient({
baseUrl: 'https://identity.example.com',
legacyJwt: true,
tokenStorage: localStorageIdentityTokenStorage(),
})
await identity.login({
identifier: '[email protected]',
password: 'secret',
kind: 'email',
})
const jwt = identity.getToken()
const legacyJwt = identity.getToken('legacy')Standard Winglet JWT is always requested. Legacy JWT is opt-in with legacyJwt: true.
Vue 3
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import { createWingletIdentity, localStorageIdentityTokenStorage } from '@creativecloud/winglet-identity'
const app = createApp(App)
app.use(createPinia())
app.use(createWingletIdentity({
baseUrl: import.meta.env.VITE_IDENTITY_URL,
legacyJwt: false,
tokenStorage: localStorageIdentityTokenStorage(),
}))Component usage:
import { useIdentityStore } from '@creativecloud/winglet-identity/vue'
const identity = useIdentityStore()
await identity.login({
identifier: email.value,
password: password.value,
kind: 'email',
})Router guard
import { createWingletAuthGuard } from '@creativecloud/winglet-identity/vue'
router.beforeEach(createWingletAuthGuard({
loginRoute: '/login',
afterLoginRoute: '/',
forbiddenRoute: '/forbidden',
}))Route metadata:
{
path: '/account',
component: AccountPage,
meta: { requiresAuth: true }
}
{
path: '/admin',
component: AdminPage,
meta: {
requiresAuth: true,
roles: ['admin'],
permissions: ['identity.read']
}
}UI route checks are convenience checks only. Backends must always enforce permissions themselves.
