1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Amplifiy】Cognito で identifyPoolId を使いたくない

Posted at

はじめに

Cognito の設定で少し詰まったので、解決した方法を載せます。参考になれば幸いです。

背景

Cognito を こちら のドキュメントの通り設定しました。私が取り組んでいたプロジェクトでは使用する予定がなかったため、identifyPoolId の項目のみを削除してみました。すると TypeScript で次のエラーが発生しました。

Type '{ userPoolId: string; userPoolClientId: string; loginWith: { email: true; }; signUpVerificationMethod: "code"; userAttributes: { email: { required: true; }; }; allowGuestAccess: true; passwordFormat: { ...; }; }' is not assignable to type 'CognitoUserPoolConfig & CognitoIdentityPoolConfig'.
  Property 'identityPoolId' is missing in type '{ userPoolId: string; userPoolClientId: string; loginWith: { email: true; }; signUpVerificationMethod: "code"; userAttributes: { email: { required: true; }; }; allowGuestAccess: true; passwordFormat: { ...; }; }' but required in type 'CognitoIdentityPoolConfig'.ts(2322)

環境

AWS Amplify Gen2 を使用しています。

解決方法

allowGuestAccess の項目も削除する。

この項目で設定している機能は、おそらく identifyPoolId がないと使用できないのかと思われます。

エラーの原因は、十分に調査しきれてないのですが、Code 1 の interface から確認できそうです。

Code 1
// 引用:https://aws-amplify.github.io/amplify-js/api/interfaces/aws_amplify.adapter_core._Reference_Types_.AuthUserPoolConfig.html

interface AuthUserPoolConfig {
    Cognito: CognitoUserPoolConfig & {
        allowGuestAccess?: undefined;
        identityPoolEndpoint?: undefined;
        identityPoolId?: undefined;
    };
}

AuthUserPoolConfig とは、Amplify の Auth の設定の interface のひとつです(参考)。Code 1 を確認すると、Cognito の設定は CognitoUserPoolConfig 型(Code 2 参照)を拡張した型であることがわかります。この拡張されている部分に、identityPoolIdallowGuestAccess が記述されています。おそらく、この辺が先のエラーを起こしてるのかと思います。

今わかっているのはここまでです。

Code 2
// 引用:https://aws-amplify.github.io/amplify-js/api/interfaces/aws_amplify.adapter_core._Reference_Types_.CognitoUserPoolConfig.html

interface CognitoUserPoolConfig {
    groups?: Record<string, UserGroupPrecedence>[];
    loginWith?: {
        email?: boolean;
        oauth?: OAuthConfig;
        phone?: boolean;
        username?: boolean;
    };
    mfa?: {
        smsEnabled?: boolean;
        status?: CognitoUserPoolConfigMfaStatus;
        totpEnabled?: boolean;
    };
    passwordFormat?: {
        minLength?: number;
        requireLowercase?: boolean;
        requireNumbers?: boolean;
        requireSpecialCharacters?: boolean;
        requireUppercase?: boolean;
    };
    signUpVerificationMethod?: "link" | "code";
    userAttributes?: Partial<Record<AuthStandardAttributeKey, {
        required: boolean;
    }>>;
    userPoolClientId: string;
    userPoolEndpoint?: string;
    userPoolId: string;
}

さいごに

ご覧いただきありがとうございました。不明な点や誤った点等ございましたらご指摘いただけると幸いです。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?