メインコンテンツへスキップ
useCurrentScreen()
現在の画面のコンテキストと状態を取得する React フックです。このフックでは、カスタム認証 UI を構築するために、クライアント設定、組織の詳細、画面の識別情報、 テナント設定、トランザクションの状態、認可パラメーターにアクセスできます。

戻り値

以下のプロパティを含む CurrentScreenOptions オブジェクトを返します。利用できない場合は null を返します。
  • client - アプリケーション識別子とメタデータ
  • organization - 組織 ID とメタデータ (Auth0 Organizations の場合)
  • prompt - 現在のプロンプト名 (例: “login”, “consent”, “mfa”)
  • screen - 現在の画面名 (例: “login-id”, “login-password”, “mfa-otp-challenge”)
  • tenant - 有効なロケールを含むテナント設定
  • transaction - トランザクションの状態、エラー配列、現在のロケール
  • untrustedData - クライアントからの認可パラメーター (使用前に検証してください)

主なポイント

  • 認証画面を条件付きでレンダリングするには screen.name を使用します
  • ネストされたプロパティは null の可能性があるため、必ずオプショナルチェーン演算子 (?.) を使用してください
  • バリデーションエラーを表示するには transaction.errors を確認します
  • 組織固有のブランディングには organization.metadata からアクセスします

戻り値

CurrentScreenOptions | null現在の画面のコンテキストデータ。利用できない場合は null
基本的な画面ルーティング
import { useCurrentScreen } from '@auth0/auth0-acul-react';

const AuthFlow = () => {
  const screenOptions = useCurrentScreen();
  const screen = screenOptions?.screen?.name || "login-id";

  switch (screen) {
    case "login-id":
      return <LoginIdScreen />;
    case "login-password":
      return <LoginPasswordScreen />;
    case "mfa-otp-challenge":
      return <MfaOtpChallengeScreen />;
    default:
      return null;
  }
};
複数のプロパティへのアクセス
import { useCurrentScreen } from '@auth0/auth0-acul-react';

const CustomAuthScreen = () => {
  const screenOptions = useCurrentScreen();
  const organizationId = screenOptions?.organization?.id;
  const errors = screenOptions?.transaction?.errors || [];
  const locale = screenOptions?.transaction?.locale || 'en';

  return (
    <div>
      {organizationId && <p>組織: {organizationId}</p>}
      {errors.map((error, i) => (
        <p key={i} className="error">{error.message}</p>
      ))}
      <p>言語: {locale}</p>
    </div>
  );
};