Need to configure your backend?See Build a Backend →
サインアウト
Amplifyは、Amplify Authなどのバックエンドリソースと対話するためのクライアントライブラリを提供します。
ユーザーをアプリケーションからサインアウトするには、signOut APIを使用します。
Future<void> signOutCurrentUser() async { final result = await Amplify.Auth.signOut(); if (result is CognitoCompleteSignOut) { safePrint('Sign out completed successfully'); } else if (result is CognitoFailedSignOut) { safePrint('Error signing user out: ${result.exception.message}'); }}すべてのデバイスからユーザーをサインアウトするグローバルサインアウトを実行することもできます。これは、ユーザーに発行されたすべてのリフレッシュトークンも無効にします。ユーザーの現在のアクセストークンとIDトークンは、リフレッシュトークンの有効期限が切れるまで他のデバイスで有効なままです(アクセストークンとIDトークンは発行後1時間で期限切れになります)。
Future<void> signOutGlobally() async { final result = await Amplify.Auth.signOut( options: const SignOutOptions(globalSignOut: true), ); if (result is CognitoCompleteSignOut) { safePrint('Sign out completed successfully'); } else if (result is CognitoPartialSignOut) { final globalSignOutException = result.globalSignOutException!; final accessToken = globalSignOutException.accessToken; // Retry the global sign out using the access token, if desired // ... safePrint('Error signing user out: ${globalSignOutException.message}'); } else if (result is CognitoFailedSignOut) { safePrint('Error signing user out: ${result.exception.message}'); }}