• 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/スキル
SKILLKnowledge Worksecurity

auth0-vue

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

次のような場合に使用: Vue 3のシングルページアプリケーション(複数の遷移画面を持つアプリ)に Auth0(多機能な認証サービス)によるログイン・ログアウト機能、保護されたページ、またはユーザーセッション(利用中の一時的な状態管理)を追加する場合。 @auth0/auth0-vue(Auth0公式のVue用ツール)と連携します。ユーザーが「Vueアプリにログイン機能を追加したい」や「Vueのページを保護したい」と述べた場合、具体的なツール名を明示していなくても、このスキルを活用してください。

原文を表示

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による認証を導入する
本文(日本語訳)

Auth0 Vue.js インテグレーション

@auth0/auth0-vue を使用して、Vue.js 3 のシングルページアプリケーション(単一のHTMLページで機能する Web アプリ)に認証機能を追加します。


前提条件

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

使用すべきでない場合

  • サーバー側でレンダリングされる Vue アプリ - Auth0 Nuxt.js ガイド をご覧ください
  • Vue 2 アプリケーション - このSDK(ソフトウェア開発キット)は Vue 3 以上が必須です。Vue 2 用の古い @auth0/auth0-spa-js ラッパーを使用してください
  • 埋め込みログイン - このSDKは Auth0 Universal Login(リダイレクト方式)を使用します
  • バックエンド 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. 認証 UI を追加

ログインコンポーネント(画面部品)を作成:

<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. 認証をテスト

開発用サーバーを起動して、ログインフローをテストします:

npm run dev

詳細ドキュメント

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

よくある間違い

間違い 解決方法
Auth0 ダッシュボードにリダイレクト URI を追加し忘れた Auth0 ダッシュボードの「Allowed Callback URLs」に、アプリケーション 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 ノンス(一度限りの値)を取得
  • setDpopNonce(nonce, id?) - サーバーから発行された DPoP ノンスを保存

よくあるユースケース:

  • ログイン/ログアウトボタン → 上記のステップ 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 による自動翻訳です。