Skip to content

Identity Verification Example ​

Verify who your customer is with Stripe Identity. The server creates a VerificationSession; verifyIdentity() from useIdentity() opens Stripe's verification modal with its client secret and resolves when the customer submits or closes it.

Try the demo ​

This demo runs in test mode: under Complete with test data, pick an outcome (for example Verification success) and click Submit, so you do not need a real ID. The demo ends with the VerificationSession ID.

Verify your identity

Stripe's modal asks for a photo ID and a selfie. In test mode, pick an outcome under Complete with test data and click Submit; no real document is needed.

Loading Stripe...

Source code ​

The code the demo above runs. Open it in StackBlitz to run and fork it with every file it imports, in Stripe test mode against the demo backend.

View source on GitHub
vue
<script setup lang="ts">
import { ref } from 'vue'
import { VueStripeProvider } from '@vue-stripe/vue-stripe'
import IdentityVerifyButton from './IdentityVerifyButton.vue'
import { useStripeConfig } from '../../composables/useStripeConfig'
import DocIcon from '../DocIcon.vue'

const { publishableKey } = useStripeConfig()

const verificationSessionId = ref<string | null>(null)

function reset() {
  verificationSessionId.value = null
}
</script>

<template>
  <div class="identity-example">
    <div v-if="!publishableKey" class="warning-box">
      <strong><DocIcon name="warning" /> Missing Configuration</strong>
      <p>Please set <code>VITE_STRIPE_PUBLISHABLE_KEY</code> in your <code>.env</code> file.</p>
    </div>

    <template v-else>
      <div v-if="!verificationSessionId" class="step-section">
        <h3>Verify your identity</h3>
        <p class="intro">
          Stripe's modal asks for a photo ID and a selfie. In test mode, pick an outcome under
          Complete with test data and click Submit; no real document is needed.
        </p>
        <VueStripeProvider :publishable-key="publishableKey">
          <IdentityVerifyButton @submitted="(id: string) => (verificationSessionId = id)" />
        </VueStripeProvider>
      </div>

      <div v-else class="success-state" data-test="identity-submitted">
        <span class="success-icon"><DocIcon name="check" :size="32" :stroke-width="2.5" /></span>
        <h3>Verification Submitted</h3>
        <p>
          Stripe processes the verification and reports the outcome to the server with the
          <code>identity.verification_session.*</code> webhooks.
        </p>
        <p class="payment-id">
          VerificationSession: <code>{{ verificationSessionId }}</code>
        </p>
        <button class="reset-btn" @click="reset">Start Over</button>
      </div>
    </template>
  </div>
</template>

<style scoped>
.identity-example {
  padding: 1.5rem;
  background: var(--vp-c-bg);
  border: 1px solid var(--vp-c-divider);
  border-radius: 12px;
}
.warning-box {
  padding: 1rem;
  background: var(--vp-c-yellow-soft);
  border: 1px solid var(--vp-c-yellow-1);
  border-radius: 8px;
  color: var(--vp-c-yellow-darker);
}
.warning-box strong {
  display: block;
  margin-bottom: 0.5rem;
}
.warning-box p {
  margin: 0;
  font-size: 0.875rem;
}
.step-section {
  padding: 1.5rem;
  background: var(--vp-c-bg-soft);
  border-radius: 8px;
}
.step-section h3 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  font-weight: 600;
}
.intro {
  margin: 0 0 1rem;
  font-size: 0.875rem;
  color: var(--vp-c-text-2);
}
.success-state {
  text-align: center;
  padding: 2rem;
}
.success-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 4rem;
  height: 4rem;
  background: var(--vp-c-green-1);
  color: white;
  border-radius: 50%;
  font-size: 2rem;
  margin-bottom: 1rem;
}
.success-state h3 {
  margin: 0 0 0.5rem 0;
  font-size: 1.25rem;
}
.success-state p {
  margin: 0.5rem 0;
  color: var(--vp-c-text-2);
}
.payment-id code {
  padding: 0.25rem 0.5rem;
  background: var(--vp-c-bg-soft);
  border-radius: 4px;
  font-size: 0.75rem;
}
.reset-btn {
  margin-top: 1.5rem;
  padding: 0.75rem 1.5rem;
  background: var(--vp-c-bg-soft);
  border: 1px solid var(--vp-c-divider);
  border-radius: 6px;
  font-size: 0.875rem;
  cursor: pointer;
}
.reset-btn:hover {
  border-color: var(--vp-c-brand-1);
  color: var(--vp-c-brand-1);
}
</style>
vue
<script setup lang="ts">
// Rendered inside VueStripeProvider so useIdentity can inject the Stripe instance.
import { ref } from 'vue'
import { useIdentity } from '@vue-stripe/vue-stripe'
import { useBackendApi } from '../../composables/useBackendApi'

const emit = defineEmits<{
  submitted: [verificationSessionId: string]
}>()

const { verifyIdentity, loading, error } = useIdentity()
const { createIdentitySession, loading: creating } = useBackendApi()

const sessionError = ref<string | null>(null)
const cancelled = ref(false)

async function verify() {
  sessionError.value = null
  cancelled.value = false
  let session
  try {
    // A new VerificationSession per attempt: the server keeps the secret key.
    session = await createIdentitySession()
  } catch (err) {
    sessionError.value =
      err instanceof Error ? err.message : 'Failed to create verification session'
    return
  }
  const result = await verifyIdentity(session.clientSecret)
  if (!result.error) {
    emit('submitted', session.verificationSessionId)
    return
  }
  // Closing the modal is not a failure worth an error box.
  if ('code' in result.error && result.error.code === 'session_cancelled') cancelled.value = true
}
</script>

<template>
  <div class="identity-verify">
    <button
      :class="['confirm-btn', { disabled: loading || creating }]"
      :disabled="loading || creating"
      data-test="identity-verify"
      @click="verify"
    >
      {{
        creating
          ? 'Creating verification session...'
          : loading
            ? 'Verification in progress...'
            : 'Verify my identity'
      }}
    </button>

    <p v-if="cancelled" class="hint" data-test="identity-cancelled">
      You closed the verification modal. Start again whenever you are ready.
    </p>
    <div v-else-if="sessionError || error" class="error-box" data-test="identity-error">
      <strong>Error:</strong> {{ sessionError || error }}
    </div>
  </div>
</template>

<style scoped>
.identity-verify {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.hint {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--vp-c-text-2);
}
.confirm-btn {
  width: 100%;
  padding: 0.875rem 1.5rem;
  background: #635bff;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}
.confirm-btn:hover:not(.disabled) {
  opacity: 0.9;
}
.confirm-btn.disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.error-box {
  padding: 0.75rem 1rem;
  background: var(--vp-c-danger-soft);
  border: 1px solid var(--vp-c-danger-1);
  border-radius: 6px;
  color: var(--vp-c-danger-1);
  font-size: 0.875rem;
}
</style>

How the demo works ​

  1. VueStripeProvider loads Stripe.js. The verify button is a child component, so it can call useIdentity().
  2. Each click asks the backend to create a new VerificationSession for a document check. The secret key stays on the server; the page receives the session's client secret and ID.
  3. verifyIdentity(clientSecret) opens Stripe's verification modal, which asks for a photo ID and a selfie, or for test data in test mode. It resolves when the customer submits or closes the modal.
  4. Without an error, the demo shows the VerificationSession ID. Closing the modal returns the error code session_cancelled, and the demo shows a hint instead of an error.
  5. The browser never learns the outcome of the check. Stripe processes the verification and reports it to the server with the identity.verification_session.* webhooks.

See also

How-to guide: Verify a customer's identity. Reference: useIdentity.