# セットアップ - アプリ用の設定

> Privyでは、アプリのログインオプションやブランディング、UI、法的ポリシーなどを簡単にカスタマイズできます。

- URL: https://cardene.dev/books/privy/069539
- 本: Privy大全 (https://cardene.dev/books/privy.md)
- 章: 4 / 42
- 前の章: https://cardene.dev/books/privy/a38941.md
- 次の章: https://cardene.dev/books/privy/c05ec3.md
- 公開日: 2023-12-22
- 更新日: 2023-12-22
- トピック: Blockchain
- タグ: solidity, ethereum, smartcontract, wallet

# 概要
Privyでは、アプリのログインオプションやブランディング、UI、法的ポリシーなどを簡単にカスタマイズできます。

Privyをアプリに設定するには、`PrivyProvider`に`config`プロパティを渡します。
以下は設定例です。

```tsx
<PrivyProvider
  appId={process.env.NEXT_PUBLIC_PRIVY_APP_ID}
  config={{
    // ログイン方法の設定
    loginMethods: ['wallet', 'email', 'google', 'twitter'],
    // アプリのブランディングとUIの設定
    appearance: {
      theme: "dark",
      accentColor: "#676FFF",
      logo: "https://your-logo-url",
      showWalletLoginFirst: true
    },
    // アプリの法的ポリシーの設定
    legal: {
      termsAndConditionsUrl: 'https://your-terms-and-conditions-url',
      privacyPolicyUrl: 'https://your-privacy-policy-url'
    }
  }}
>
```

この`config`を使って、次のことができます。

- ユーザーに提示するログインオプションの設定
- PrivyのUIの外観をブランドに合わせてカスタマイズ
- アプリの利用規約やプライバシーポリシーを表示して、ユーザーに情報を提供

# ログイン方法の設定
アプリのログイン方法を設定するには、`config`プロパティに`loginMethods`配列を渡します。

```tsx
<PrivyProvider
  appId={process.env.NEXT_PUBLIC_PRIVY_APP_ID}
  config={{
    appearance: {
      // This configures your login modal to show wallet login options above other options.
      showWalletLoginFirst: true,
    },
    // This configures wallet, email, Google, and Twitter login for your app.
    loginMethods: ['wallet', 'email', 'google', 'twitter']
  }}
>
```

サポートされているログイン方法には、「**wallet**」、「**email**」、「**sms**」、「**google**」、「**twitter**」、「**discord**」、「**github**」、「**apple**」があります。
ログインモーダルでのログインオプションの順序もカスタマイズできます。

![ログイン方法の設定の図](/images/zenn-1d1238b1a36f-20231218.webp)
*https://docs.privy.io/guide/configuration/*

# ブランディング
PrivyのUIの外観をブランドに合わせてカスタマイズするには、`config`プロパティに`appearance`オブジェクトを渡します。

```tsx
<PrivyProvider
  appId={process.env.NEXT_PUBLIC_PRIVY_APP_ID}
  config={{
    appearance: {
      theme: "dark",
      accentColor: "#676FFF",
      logo: "https://your-logo-url",
      showWalletLoginFirst: true
    }
  }}
>
```

このオブジェクトには以下のパラメータを含めることができます。

- `theme`
	- モーダルの全体的なカラースキーム。
- `accentColor`
	- アクティブ状態、CTA、その他に使用されるアクセントカラー。
- `logo`
	- アプリのロゴ。
- `showWalletLoginFirst`
	- ウォレットログインオプションを他のログインオプションの上または下に表示するかどうか。

## テーマ (`theme`)
モーダルの全体的なカラースキームを設定します。
選択肢には「**light**」（標準のPrivyライトテーマ）、「**dark**」（標準のPrivyダークテーマ）、またはカスタムの16進数カラーコード（例：`'#13152F'`）があります。
カスタムカラーを設定すると、その色がPrivyモーダルの主要な背景色として使用され、他の色は自動的に生成されます。
これにより、アプリのブランディングに合った統一感のあるパレットが作成されます。
必要に応じて、これら自動生成される色を上書きして、ブランドのカラーパレットに更に合わせることもできます。

## アクセントカラー (`accentColor`)
アクティブな状態、呼びかけ（CTA）、アプリケーション全体のアクセントに使用される色です。
任意の16進数カラーコードを文字列として設定できます。
指定しない場合、Privyのデフォルトのアクセントカラー`#696FFD`が使用されます。

## ロゴ (`logo`)
ログインモーダルに表示されるアプリのロゴです。
ホストされた画像のURLを提供する必要があります。
最適な結果を得るために、4:1のアスペクト比を持つSVG形式の画像を推奨します。

## ログインオプションの順序 (`showWalletLoginFirst`)
ログインモーダルでウォレットログインオプションを他のログインオプション（メール、SMS、ソーシャルなど）の上または下に表示するかどうかを決定します。
デフォルトでは`true`に設定されています。
アプリが初心者ユーザーよりもネイティブユーザーにフォーカスしている場合、このプロパティを`false`に設定して、より馴染みのあるログイン方法を優先させることができます。

さらにPrivyのUIをカスタマイズしたい場合は、ログインモーダルの特定の色を明示的に上書きすることも可能です。
これは、デフォルトのPrivyテーマ（「**light**」または「**dark**」）を使用していて特定の色を調整したい場合や、カスタムテーマを設定し、自動生成される色の代わりに正確なブランドカラーを使用したい場合に便利です。

Privyモーダルの色を明示的に上書きするには、アプリのCSSの`:root`に対応するCSS変数を追加し、カスタムカラーに設定します。

```css
:root {
  --privy-border-radius-sm: 'your-custom-value';
  --privy-border-radius-md: 'your-custom-value';
  --privy-border-radius-lg: 'your-custom-value';
  --privy-border-radius-full: 'your-custom-value';
  --privy-color-background: 'your-custom-value';
  --privy-color-background-2: 'your-custom-value';
  --privy-color-foreground: 'your-custom-value';
  --privy-color-foreground-2: 'your-custom-value';
  --privy-color-foreground-3: 'your-custom-value';
  --privy-color-foreground-4: 'your-custom-value';
  --privy-color-foreground-accent: 'your-custom-value';
  --privy-color-accent: 'your-custom-value';
  --privy-color-accent-light: 'your-custom-value';
  --privy-color-accent-dark: 'your-custom-value';
  --privy-color-success: 'your-custom-value';
  --privy-color-error: 'your-custom-value';
}
```

可能なCSS変数は上記の通りです。
異なる色の組み合わせを実験するためにブラウザの開発者ツールを使用し、アプリに最適な色合いを見つけることができます。

# 法的ポリシー
ユーザーがアプリにログインする時、Privyを使用してアプリの法的ポリシーに同意を求めることができます。
これには、`config`プロパティに`legal`オブジェクトを渡し、`termsAndConditionsUrl`および`privacyPolicyUrl`を文字列として提供します。

```tsx
<PrivyProvider
  appId={process.env.NEXT_PUBLIC_PRIVY_APP_ID}
  config={{
    legal: {
      termsAndConditionsUrl: 'https://your-terms-and-conditions-url',
      privacyPolicyUrl: 'https://your-privacy-policy-url'
    }
  }}
>
```

これらのポリシーはアプリのログインモーダルからリンクされ、ユーザーはログイン時にこれらに同意する必要があります。

# UIの設定例

:::details Light
```js
const config = {
  appearance: {
    theme: 'light',
    logo: 'light-logo-url'
  }
};
```
![UIの設定例の図](/images/zenn-6a3d41270eed-20231218.webp)
*https://docs.privy.io/guide/configuration/*
:::

:::details Dark
```js
const config = {
  appearance: {
    theme: 'dark',
    logo: 'dark-logo-url'
  }
};
```
![UIの設定例の図](/images/zenn-8be1dcae2eb3-20231218.webp)
*https://docs.privy.io/guide/configuration/*
:::

:::details Cream(Custom)
```js
const config = {
  appearance: {
    theme: '#FCF7EE',
    accentColor: '#38CCCD'
    logo: 'light-logo-url'
  }
}
```
![UIの設定例の図](/images/zenn-fd8f7c801ff9-20231218.webp)
*https://docs.privy.io/guide/configuration/*
:::

:::details Forest (Custom)
```js
const config = {
  appearance: {
    theme: '#425047',
    accentColor: '#A7C080'
    logo: 'dark-logo-url'
  }
}
```
![UIの設定例の図](/images/zenn-8d2251f94b03-20231218.webp)
*https://docs.privy.io/guide/configuration/*
:::

# 実装例

```ts
<PrivyProvider
	appId={PRIVY_APP_ID}
      onSuccess={handleLogin}
      config={{
        // Configure your app's login methods
        loginMethods: ["wallet", "email", "google", "twitter"],
        // Configure your app's branding and UIs
        appearance: {
          theme: "#02343F",
          accentColor: "#F0EDCC",
          logo: "https://res.cloudinary.com/dplp5wtzk/image/upload/v1702903792/cardene.png",
          showWalletLoginFirst: true,
        },
        // Configure your app's legal policies
        legal: {
          termsAndConditionsUrl: "https://your-terms-and-conditions-url",
          privacyPolicyUrl: "https://your-privacy-policy-url",
        },
      }}
>
      {children}
</PrivyProvider>
```

![実装例の図](/images/zenn-2bd432bea1fd-20231218.webp)

# コード

https://github.com/cardene777/privy/commit/3c8508b2594189c7533dfc5ffcace9deae26b841

# 参考

https://docs.privy.io/guide/configuration/
