Documentation

Vue quick start

Add sign-in to a Vue 3 app with the plugin, a route guard and ready-made components.

All documentation

Before you start

  • Create a workspace at https://auth.ziqme.com/signup. It starts on the Free plan; no card is needed.
  • Open https://app.ziqme.com/auth-admin, choose "Register application", and add your redirect URI. A browser or mobile app is a public application (no secret). A server is confidential and gets a client secret, shown once.
  • Note the client ID (it starts with app_). It is safe to ship in a browser: it is not a secret.

The SDK and component packages are not on npm or NuGet yet. For early access, contact Ziqme support at https://ziqme.com/contact. Meanwhile any standard OpenID Connect or JWT library works against Auth: every step here also works with one; see the plain OIDC quick start.

Install the plugin

main.ts
import { createApp } from 'vue'
import { createAuthGuard, createZiqmeAuth } from '@smartdesk/auth-vue'
import App from './App.vue'
import router from './router'

const ziqmeAuth = createZiqmeAuth({
  issuer: 'https://auth.ziqme.com',
  clientId: 'app_your_client_id',
  redirectUri: `${location.origin}/callback`,
  postLogoutRedirectUri: `${location.origin}/`,
  applicationName: 'Bistro',
  onSignedIn: returnTo => router.replace(returnTo),
})

router.beforeEach(createAuthGuard(ziqmeAuth))
createApp(App).use(router).use(ziqmeAuth).mount('#app')

Register /callback as a redirect URI and add a route for it; the plugin finishes the sign-in there and calls onSignedIn with the page the person was going to.

Protect routes

router.ts
const routes = [
  { path: '/', component: Home },
  { path: '/callback', component: { render: () => null } },
  { path: '/orders', component: Orders, meta: { requiresAuth: true } },
  { path: '/admin', component: Admin, meta: { requiresAuth: true, roles: ['manager'] } },
]

An anonymous visitor to a protected route is sent to the hosted login and returns to the same route. A signed-in person without one of the route's roles is sent to "/" instead, because signing in again would not help.

Use the components

App.vue
<script setup lang="ts">
import { SignIn, UserButton, useAuth } from '@smartdesk/auth-vue'

const { isLoaded, isSignedIn, user, getAccessToken } = useAuth()

async function loadOrders() {
  const response = await fetch('/api/orders', {
    headers: { Authorization: `Bearer ${await getAccessToken()}` },
  })
  return response.json()
}
</script>

<template>
  <UserButton v-if="isSignedIn" show-name />
  <SignIn v-else-if="isLoaded" />
</template>

SignIn shows a card whose button goes to the hosted login. Passwords and MFA codes are typed there, never into your app. UserButton, UserProfile and OrganizationSwitcher render the signed-in person; SignUp explains that accounts come by invitation, or links to your own registration page.

Languages and theme

English and Persian are built in, and Persian renders right to left. Pass locale (a ref follows your own language switch) and messages to replace any wording. Pass appearance, or set the --ziqme-auth-* custom properties in your stylesheet.

Theme
createZiqmeAuth({
  // ...
  locale: 'fa',
  appearance: { colorScheme: 'auto', variables: { primary: '#16a34a', radius: '12px' } },
})