メインコンテンツへスキップ

セットアップの要件

Auth0の構成が必要 - テナントがMy Organization APIで構成されていることを 確認してください。セットアップガイドを表示 →

インストール

pnpm add @auth0/universal-components-react
shadcnコマンドを実行すると、共有ユーティリティとAuth0統合の@auth0/universal-components-core 依存関係もインストールされます。

クイックスタート

import { OrganizationDetailsEdit } from '@auth0/universal-components-react/spa';

export function OrganizationSettingsPage() {
  const navigate = useNavigate();

return (

<OrganizationDetailsEdit
saveAction={{
        onAfter: () => navigate("/organization"),
      }}
backButton={{
        onClick: () => navigate("/organization"),
      }}
/>
);
}

この例ではReact SPAを使用していますが、prop構成(schema、customMessages、stylingなど)はNext.jsやshadcnのセットアップにも同様に適用されます。
import React from "react";
import { OrganizationDetailsEdit } from "@auth0/universal-components-react/spa";
import { Auth0Provider } from "@auth0/auth0-react";
import { Auth0ComponentProvider } from "@auth0/universal-components-react/spa";
import { useNavigate } from "react-router-dom";
import { analytics } from "./lib/analytics";

function OrganizationSettingsPage() {
  const navigate = useNavigate();

  const handleSaveSuccess = (org) => {
    analytics.track("Organization Updated", {
      name: org.name,
      displayName: org.display_name,
    });
    navigate("/organization");
  };

  return (
    <div className="max-w-2xl mx-auto p-6">
      <OrganizationDetailsEdit
        schema={{
          details: {
            displayName: {
              required: true,
              maxLength: 100,
            },
            color: {
              regex: /^#[0-9A-Fa-f]{6}$/,
              errorMessage: "有効な16進数の色を入力してください",
            },
          },
        }}
        saveAction={{
          onBefore: (org) => {
            return confirm(`"${org.display_name}"への変更を保存しますか?`);
          },
          onAfter: handleSaveSuccess,
        }}
        cancelAction={{
          onBefore: () => confirm("保存されていない変更を破棄しますか?"),
          onAfter: () => navigate("/organization"),
        }}
        backButton={{
          onClick: () => navigate("/organization"),
        }}
        customMessages={{
          header: {
            title: "Organizationの設定",
          },
          notifications: {
            save_success: "設定が正常に保存されました",
          },
        }}
        styling={{
          variables: {
            common: {
              "--color-primary": "#059669",
            },
          },
          classes: {
            "OrganizationDetailsEdit-form": "shadow-xl rounded-lg",
          },
        }}
      />
    </div>
  );
}

export default function App() {
  const authDetails = {
    domain: "your-domain.auth0.com",
    clientId: "your-client-id",
  };
  return (
    <Auth0Provider
      {...authDetails}
      redirectUri={window.location.origin}
      authorizationParams={{
        redirect_uri: window.location.origin,
      }}
    >
      <Auth0ComponentProvider>
        <OrganizationSettingsPage />
      </Auth0ComponentProvider>
    </Auth0Provider>
  );
}

Props

Core Props

Core propsは、コンポーネントの操作の基礎です。OrganizationDetailsEditの場合、必須のpropはありません。My Organization APIから現在のOrganization情報が自動で読み込まれます。

Display Props

Display propsは、コンポーネントのレンダリングを、その動作に影響することなく制御します。セクションを非表示にする場合、または読み取り専用モードを有効にする場合に使用します。
Prop種類説明
readOnlybooleanすべてのフォームの入力を無効にします。デフォルト値:false
hideHeaderbooleanヘッダーセクションを非表示にします。デフォルト値:false

Action Props

Action propsはユーザーインタラクションを処理し、ユーザーが変更を保存したときやキャンセルしたときに何が起こるかを定義します。ライフサイクルフック(onBeforeonAfter)を使用して、アプリケーションのルーティングや分析と連携できます。
Prop種類説明
saveActionComponentAction<OrganizationPrivate>変更を保存するアクション。詳細
cancelActionComponentAction<OrganizationPrivate>変更をキャンセル/破棄するアクション。詳細
backButtonObject[戻る]ボタンの構成。 詳細

saveAction

種類:ComponentAction<OrganizationPrivate> ユーザーがOrganizationの変更を送信した際の保存フローを制御します。保存が成功した後に別のページに移動するには、onAfterを使用します。 プロパティ:
  • disabled - [保存]ボタンを無効にします(たとえば、別の処理が進行中である場合)
  • onBefore(data) - 保存操作前に実行します。保存を防ぐ場合はfalseを返します(確認のダイアログを表示する場合など)。
  • onAfter(data) - Organizationが正常に保存された後で実行します。別のページに移動する場合、またはイベントを追跡する場合に使用します。
共通のパターン:
// Navigate back after saving
saveAction={{
  onAfter: () => navigate("/organization"),
}}

// Add confirmation before saving
saveAction={{
  onBefore: (org) => {
    return confirm(`"${org.display_name}"への変更を保存しますか?`);
  },
  onAfter: () => navigate("/organization"),
}}

// Track analytics on save
saveAction={{
  onAfter: (org) => {
    analytics.track("Organization Updated", {
      name: org.name,
      displayName: org.display_name,
    });
    navigate("/organization");
  },
}}

cancelAction

種類:ComponentAction<OrganizationPrivate> キャンセル/破棄のフローを制御します。破棄された変更を管理する際には、このアクションを使用します。 プロパティ:
  • disabled -[キャンセル]ボタンを無効にします
  • onBefore(data) - キャンセル操作の前に実行します。キャンセルを防ぐ場合はfalseを返します(保存されていない変更の破棄を確認する場合など)。
  • onAfter(data) - キャンセルの確認後に実行します。フォームから移動する場合に使用します。
例:
<OrganizationDetailsEdit
  cancelAction={{
    onBefore: (org) => {
      return confirm("保存されていない変更を破棄しますか?");
    },
    onAfter: () => navigate("/organization"),
  }}
/>

backButton

種類:{ icon?: LucideIcon; onClick: (e: MouseEvent) => void } コンポーネントヘッダー内の[戻る]ボタンを構成します。これを使ってOrganizationの概要または前のページに戻ります。 プロパティ:
  • icon - Lucide iconのカスタムコンポーネント(任意、デフォルト値はArrowLeft)
  • onClick - ナビゲーション用クリックハンドラー
例:
import { ChevronLeft } from "lucide-react";

<OrganizationDetailsEdit
  backButton={{
    icon: ChevronLeft,
    onClick: () => navigate("/organization"),
  }}
/>;

Customization Props

Customization propsを使うと、ソースコードに変更を加えることなく、コンポーネントをブランド・ロケール・検証要件に合わせることができます。
Prop種類説明
schemaOrganizationDetailsEditSchemasフィールド検証ルール。詳細
customMessagesPartial<OrganizationDetailsEditMessages>i18nテキストのオーバーライド。詳細
stylingComponentStyling<OrganizationEditClasses>CSS変数とクラスのオーバーライド。詳細

schema

Organizationの詳細フィールド用にカスタム検証ルールを設定します。
すべてのスキーマフィールドがサポート:regexerrorMessageminLengthmaxLengthrequireddetails.name - Organizationの内部名 details.displayName - Organizationの表示名 details.color - ブランドカラー(16進数形式) details.logoURL - ロゴのURL
<OrganizationDetailsEdit
  schema={{
    details: {
      name: {
        minLength: 3,
        maxLength: 50,
        regex: /^[a-zA-Z0-9-_]+$/,
        errorMessage: "名前には英数字、ハイフン、アンダースコア以外使用できません。",
      },
      displayName: {
        required: true,
        maxLength: 100,
      },
      color: {
        regex: /^#[0-9A-Fa-f]{6}$/,
        errorMessage: "有効な16進数の色を入力してください(例:#FF5500)",
      },
      logoURL: {
        regex: /^https:\/\/.+/,
        errorMessage: "ロゴのURLはHTTPSでなければなりません",
      },
    },
  }}
/>

customMessages

すべてのテキストと翻訳をカスタマイズします。フィールドはすべて任意で、入力しなかった場合はデフォルト値が使用されます。
header - コンポーネントのヘッダー
  • titledescriptionback_button_text
form - フォームフィールド
  • fields.name - labelplaceholderhelper_texterror
  • fields.display_name - labelplaceholderhelper_texterror
  • fields.color - labelplaceholderhelper_texterror
  • fields.logo_url - labelplaceholderhelper_texterror
actions - ボタンラベル
  • save_button_textcancel_button_text
notifications - API応答
  • save_successsave_errorgeneral_error
<OrganizationDetailsEdit
  customMessages={{
    header: {
      title: "Organizationを編集",
      description: "Organizationの設定を更新",
    },
    form: {
      fields: {
        name: {
          label: "Organization ID",
          helper_text: "内部識別子(作成後は変更できません)",
        },
        display_name: {
          label: "Organizationの名前",
          placeholder: "表示名を入力",
        },
      },
    },
    notifications: {
      save_success: "Organizationが正常に更新されました",
    },
  }}
/>

styling

CSS変数とクラスのオーバーライドを使って外観をカスタマイズします。テーマ認識型のスタイルをサポートします。
Variables - CSSカスタムプロパティ
  • common - すべてのテーマに適用
  • light - ライトテーマのみ
  • dark - ダークテーマのみ
Classes - コンポーネントクラスのオーバーライド
  • OrganizationDetailsEdit-header
  • OrganizationDetailsEdit-form
  • OrganizationDetailsEdit-actions
<OrganizationDetailsEdit
  styling={{
    variables: {
      common: {
        "--font-size-title": "1.5rem",
      },
      light: {
        "--color-primary": "#059669",
      },
    },
    classes: {
      "OrganizationDetailsEdit-form": "shadow-lg rounded-xl p-6",
    },
  }}
/>

高度なカスタマイズ

OrganizationDetailsEditコンポーネントは、小さいサブコンポーネントとフックで構成されます。shadcnを使用する場合は、個別にインポートしてカスタムのOrganization編集ワークフローを構築することができます。

利用可能なサブコンポーネント

高度なユースケースの場合は、個々のサブコンポーネントをインポートしてカスタムのOrganization編集インターフェイスを構築することができます。
コンポーネント説明
OrganizationFormすべてのフィールドを持つメインフォームコンポーネント
ColorPickerFieldブランドカラー選択フィールド
LogoUploadFieldプレビュー付きのロゴのURL入力

利用可能なフック

これらのフックは、UIなしで内在のロジックを提供します。フックを使用すると、Auth0 API統合を利用しながら完全にカスタムなインターフェイスが構築できます。
フック説明
useOrganizationDetailsEditOrganization編集ロジックとAPIの統合