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

Page updated May 17, 2024

Sign-out

Amplify provides a client library that enables you to interact with backend resources such as Amplify Auth.

The quickest way to get started with Amplify Auth in your frontend application is with the Authenticator component, which provides a customizable UI and complete authentication flows.

To sign a user out of your application use the 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}');
}
}

You can also sign out users from all devices by performing a global sign-out. This will also invalidate all refresh tokens issued to a user. The user's current access and ID tokens will remain valid on other devices until the refresh token expires (access and ID tokens expire one hour after they are issued).

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}');
}
}