• Projects
  • Service
  • About
  • branding.bz
  • Podcast
  • Tips
  • FAQ
  • Recruit
  • Download
  • Contact
  • branding.bz(ブランド構築SaaS)
  • DESIGN NOW(デザインメディア)
  • X
  • LinkedIn
  • Spotify
  • Facebook

213-0011 神奈川県川崎市高津区久本3-6-7-303

© 2026 ID INC. All rights reserved

claude-skills/スキル
SKILLOfficialsecurity

auth0-vue

プラグイン
auth0
ライセンス
Apache-2.0
ソース
GitHub で見る ↗
説明

次のような場合に使用: Vue 3 のシングルページアプリケーション(単一ファイルで動作するウェブアプリ)に Auth0 によるログイン機能、ログアウト機能、保護されたページ、またはユーザーセッション管理を追加する場合。 @auth0/auth0-vue というライブラリとの連携に対応しており、ユーザーが「Vue アプリにログイン機能を追加したい」や「Vue のページを保護したい」と述べた場合でも、SDK の名前を明示していなければこのスキルを使用します。

原文を表示

Use when adding Auth0 login, logout, protected routes, or user sessions to a Vue 3 SPA. Integrates @auth0/auth0-vue — use even if the user says "add login to my Vue app" or "protect my Vue routes" without naming the SDK.

ユースケース
  • Vue 3 アプリにログイン機能を追加する
  • ログアウト機能を実装する
  • 保護されたページを作成する
  • ユーザーセッション管理を設定する
本文(日本語訳)

Auth0 Vue.js 統合

Vue.js 3 シングルページアプリケーションに対して、@auth0/auth0-vue を使用した認証機能を追加します。


前提条件

  • Vue 3 以上のアプリケーション(Vite または Vue CLI)
  • Auth0 のアカウントとアプリケーション設定
  • Auth0 をまだ設定していない場合は、事前に auth0-quickstart スキルを使用してください

使用しない場合

  • サーバーサイドレンダリング(サーバー側で画面を生成する方式)の Vue アプリ - Auth0 Nuxt.js ガイドを参照してください
  • Vue 2 アプリケーション - このSDK(開発キット)は Vue 3 以上が必須です。レガシー版の @auth0/auth0-spa-js を使用してください
  • 埋め込みログイン - このSDKは Auth0 ユニバーサルログイン(リダイレクト方式)を使用しています
  • バックエンド API 認証 - express-openid-connect または JWT 検証を使用してください

クイックスタートの手順

1. SDK をインストール

npm install @auth0/auth0-vue

2. 環境を設定

Auth0 CLI を使った自動設定の場合、セットアップガイドの完全なスクリプトを参照してください。

手動設定の場合:

.env ファイルを作成してください:

VITE_AUTH0_DOMAIN=your-tenant.auth0.com
VITE_AUTH0_CLIENT_ID=your-client-id

3. Auth0 プラグインを設定

src/main.ts を編集してください:

import { createApp } from 'vue';
import { createAuth0 } from '@auth0/auth0-vue';
import App from './App.vue';

const app = createApp(App);

app.use(
  createAuth0({
    domain: import.meta.env.VITE_AUTH0_DOMAIN,
    clientId: import.meta.env.VITE_AUTH0_CLIENT_ID,
    authorizationParams: {
      redirect_uri: window.location.origin
    }
  })
);

app.mount('#app');

4. 認証画面を追加

ログインコンポーネントを作成してください:

<script setup lang="ts">
import { useAuth0 } from '@auth0/auth0-vue';

const { loginWithRedirect, logout, isAuthenticated, user, isLoading } = useAuth0();
</script>

<template>
  <div>
    <div v-if="isLoading">読み込み中...</div>

    <div v-else-if="isAuthenticated">
      <img :src="user?.picture" :alt="user?.name" />
      <span>ようこそ、{{ user?.name }}</span>
      <button @click="logout({ logoutParams: { returnTo: window.location.origin }})">
        ログアウト
      </button>
    </div>

    <button v-else @click="loginWithRedirect()">
      ログイン
    </button>
  </div>
</template>

5. 認証をテスト

開発サーバーを起動してログイン流れをテストしてください:

npm run dev

詳細ドキュメント

  • セットアップガイド - 自動セットアップスクリプト(Bash/PowerShell)、CLI コマンド、手動設定
  • 統合ガイド - 保護されたページ、API呼び出し、エラーハンドリング、再利用可能な関数(composables)
  • API リファレンス - SDK 完全仕様、設定オプション、再利用可能な関数リファレンス、テスト戦略

よくあるミス

ミス 解決方法
Auth0 ダッシュボードにリダイレクト URI を追加し忘れた Auth0 ダッシュボードの「Allowed Callback URLs(許可されたコールバック URL)」に、アプリケーション URL(例:http://localhost:3000、https://app.example.com)を追加してください
環境変数の接頭辞が間違っている Vite は VITE_ 接頭辞が必須、Vue CLI は VUE_APP_ です
読み込み状態を処理していない 認証に関連した UI を描画する前に、常に isLoading を確認してください
トークンを localStorage に保存している トークンを手動で保存しないでください。SDK が安全に自動保存します
createAuth0 プラグインの登録を忘れた アプリをマウントする前に、必ず app.use(createAuth0({...})) を実行してください
プラグインが読み込まれる前に認証にアクセスしている 認証に関連したコードを v-if="!isLoading" でラップしてください

関連スキル

  • auth0-quickstart - Auth0 の基本セットアップ
  • auth0-migration - 他の認証サービスからの移行
  • auth0-mfa - 多要素認証の追加
  • auth0-dpop - DPoP(デバイス連携トークン)の追加
  • auth0-cli - ターミナルから Auth0 リソースを管理

クイックリファレンス

主要な再利用可能関数:

  • useAuth0() - メイン認証関数
  • isAuthenticated - ユーザーがログイン状態かリアルタイム確認
  • user - ユーザーのプロフィール情報をリアルタイム取得
  • loginWithRedirect() - ログイン開始
  • logout() - ログアウト
  • getAccessTokenSilently() - API 呼び出し用のアクセストークン取得

DPoP(デバイス連携トークン)関連の関数 (createAuth0 設定で useDpop: true が必須 — auth0-dpop を参照):

  • createFetcher(config) - DPoP 対応の fetch 互換関数を返す
  • generateDpopProof(params) - DPoP 証明 JWT を手動生成
  • getDpopNonce(id?) - 現在保存されている DPoP nonce(一度限りの値)を取得
  • setDpopNonce(nonce, id?) - サーバー発行の DPoP nonce を保存

よくあるユースケース:

  • ログイン/ログアウトボタン → 上記ステップ4 を参照
  • 保護されたページとナビゲーション制御 → 統合ガイド
  • トークン付き API 呼び出し → 統合ガイド
  • エラーハンドリング → 統合ガイド

参考資料

  • Auth0 Vue SDK ドキュメント
  • Auth0 Vue クイックスタート
  • SDK GitHub リポジトリ
原文(English)を表示

Auth0 Vue.js Integration

Add authentication to Vue.js 3 single-page applications using @auth0/auth0-vue.


Prerequisites

  • Vue 3+ application (Vite or Vue CLI)
  • Auth0 account and application configured
  • If you don't have Auth0 set up yet, use the auth0-quickstart skill first

When NOT to Use

  • Server-side rendered Vue apps - See Auth0 Nuxt.js guide for SSR patterns
  • Vue 2 applications - This SDK requires Vue 3+, use legacy @auth0/auth0-spa-js wrapper
  • Embedded login - This SDK uses Auth0 Universal Login (redirect-based)
  • Backend API authentication - Use express-openid-connect or JWT validation instead

Quick Start Workflow

1. Install SDK

npm install @auth0/auth0-vue

2. Configure Environment

For automated setup with Auth0 CLI, see Setup Guide for complete scripts.

For manual setup:

Create .env file:

VITE_AUTH0_DOMAIN=your-tenant.auth0.com
VITE_AUTH0_CLIENT_ID=your-client-id

3. Configure Auth0 Plugin

Update src/main.ts:

import { createApp } from 'vue';
import { createAuth0 } from '@auth0/auth0-vue';
import App from './App.vue';

const app = createApp(App);

app.use(
  createAuth0({
    domain: import.meta.env.VITE_AUTH0_DOMAIN,
    clientId: import.meta.env.VITE_AUTH0_CLIENT_ID,
    authorizationParams: {
      redirect_uri: window.location.origin
    }
  })
);

app.mount('#app');

4. Add Authentication UI

Create a login component:

<script setup lang="ts">
import { useAuth0 } from '@auth0/auth0-vue';

const { loginWithRedirect, logout, isAuthenticated, user, isLoading } = useAuth0();
</script>

<template>
  <div>
    <div v-if="isLoading">Loading...</div>

    <div v-else-if="isAuthenticated">
      <img :src="user?.picture" :alt="user?.name" />
      <span>Welcome, {{ user?.name }}</span>
      <button @click="logout({ logoutParams: { returnTo: window.location.origin }})">
        Logout
      </button>
    </div>

    <button v-else @click="loginWithRedirect()">
      Login
    </button>
  </div>
</template>

5. Test Authentication

Start your dev server and test the login flow:

npm run dev

Detailed Documentation

  • Setup Guide - Automated setup scripts (Bash/PowerShell), CLI commands, manual configuration
  • Integration Guide - Protected routes, API calls, error handling, composables
  • API Reference - Complete SDK API, configuration options, composables reference, testing strategies

Common Mistakes

Mistake Fix
Forgot to add redirect URI in Auth0 Dashboard Add your application URL (e.g., http://localhost:3000, https://app.example.com) to Allowed Callback URLs in Auth0 Dashboard
Using wrong env var prefix Vite requires VITE_ prefix, Vue CLI uses VUE_APP_
Not handling loading state Always check isLoading before rendering auth-dependent UI
Storing tokens in localStorage Never manually store tokens - SDK handles secure storage automatically
Missing createAuth0 plugin registration Must call app.use(createAuth0({...})) before mounting app
Accessing auth before plugin loads Wrap auth-dependent code in v-if="!isLoading"

Related Skills

  • auth0-quickstart - Basic Auth0 setup
  • auth0-migration - Migrate from another auth provider
  • auth0-mfa - Add Multi-Factor Authentication
  • auth0-dpop - Add DPoP device-bound token binding
  • auth0-cli - Manage Auth0 resources from the terminal

Quick Reference

Core Composables:

  • useAuth0() - Main authentication composable
  • isAuthenticated - Reactive check if user is logged in
  • user - Reactive user profile information
  • loginWithRedirect() - Initiate login
  • logout() - Log out user
  • getAccessTokenSilently() - Get access token for API calls

DPoP Composables (requires useDpop: true in createAuth0 config — see auth0-dpop):

  • createFetcher(config) - Returns a DPoP-aware fetch-compatible function
  • generateDpopProof(params) - Manually generate a DPoP proof JWT
  • getDpopNonce(id?) - Get the current stored DPoP nonce
  • setDpopNonce(nonce, id?) - Store a server-issued DPoP nonce

Common Use Cases:

  • Login/Logout buttons → See Step 4 above
  • Protected routes with navigation guards → Integration Guide
  • API calls with tokens → Integration Guide
  • Error handling → Integration Guide

References

  • Auth0 Vue SDK Documentation
  • Auth0 Vue Quickstart
  • SDK GitHub Repository

原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。