Name:
interface
Value:
Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

サインアップ

Amplifyは、Amplify Authなどのバックエンドリソースと対話できるクライアントライブラリを提供します。

Amplify Authをフロントエンドアプリケーションで最も簡単に始める方法は、Authenticatorコンポーネントを使用することです。このコンポーネントはカスタマイズ可能なUIと完全な認証フローを提供します。

まず、signUp() APIを使用してバックエンドに新しいユーザーを作成できます:

/// ユーザー名、パスワード、メールアドレスを使用してユーザーをサインアップします。
/// 必須属性は、アプリの設定によって異なる場合があります。
Future<void> signUpUser({
required String username,
required String password,
required String email,
String? phoneNumber,
}) async {
try {
final userAttributes = {
AuthUserAttributeKey.email: email,
if (phoneNumber != null) AuthUserAttributeKey.phoneNumber: phoneNumber,
// additional attributes as needed
};
final result = await Amplify.Auth.signUp(
username: username,
password: password,
options: SignUpOptions(
userAttributes: userAttributes,
),
);
await _handleSignUpResult(result);
} on AuthException catch (e) {
safePrint('Error signing up user: ${e.message}');
}
}
Future<void> _handleSignUpResult(SignUpResult result) async {
switch (result.nextStep.signUpStep) {
case AuthSignUpStep.confirmSignUp:
final codeDeliveryDetails = result.nextStep.codeDeliveryDetails!;
_handleCodeDelivery(codeDeliveryDetails);
break;
case AuthSignUpStep.done:
safePrint('Sign up is complete');
break;
}
}
void _handleCodeDelivery(AuthCodeDeliveryDetails codeDeliveryDetails) {
safePrint(
'A confirmation code has been sent to ${codeDeliveryDetails.destination}. '
'Please check your ${codeDeliveryDetails.deliveryMedium.name} for the code.',
);
}

signUp APIレスポンスには nextStep プロパティが含まれており、これを使用して追加のアクションが必要かどうかを判定できます。以下のネクストステップが返される可能性があります:

ネクストステップ説明
confirmSignUpサインアップをユーザーからコードを収集して confirmSignUp を呼び出すことで確認する必要があります。
doneサインアッププロセスが完全に完了しました。

サインアップの確認

デフォルトでは、サインアップしたすべてのユーザーは、メールアドレスまたは電話番号に送信された確認コードで確認するまで、未確認のステータスのままです。以下は、loginWith オプションとして phone または email が使用される場合に使用されるデフォルトの検証方法です。

ログインオプションユーザーアカウント検証チャネル
phone電話番号
emailメール
emailphoneメール

ユーザーから確認コードを受け取った後、サインアップを確認できます:

Future<void> confirmUser({
required String username,
required String confirmationCode,
}) async {
try {
final result = await Amplify.Auth.confirmSignUp(
username: username,
confirmationCode: confirmationCode,
);
// Check if further confirmations are needed or if
// the sign up is complete.
await _handleSignUpResult(result);
} on AuthException catch (e) {
safePrint('Error confirming user: ${e.message}');
}
}