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

Page updated May 21, 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.

Amplify.Auth.signOut( signOutResult -> {
if (signOutResult instanceof AWSCognitoAuthSignOutResult.CompleteSignOut) {
// Sign Out completed fully and without errors.
Log.i("AuthQuickStart", "Signed out successfully");
} else if (signOutResult instanceof AWSCognitoAuthSignOutResult.PartialSignOut) {
// Sign Out completed with some errors. User is signed out of the device.
AWSCognitoAuthSignOutResult.PartialSignOut partialSignOutResult =
(AWSCognitoAuthSignOutResult.PartialSignOut) signOutResult;
HostedUIError hostedUIError = partialSignOutResult.getHostedUIError();
if (hostedUIError != null) {
Log.e("AuthQuickStart", "HostedUI Error", hostedUIError.getException());
// Optional: Re-launch hostedUIError.getUrl() in a Custom tab to clear Cognito web session.
}
GlobalSignOutError globalSignOutError = partialSignOutResult.getGlobalSignOutError();
if (globalSignOutError != null) {
Log.e("AuthQuickStart", "GlobalSignOut Error", globalSignOutError.getException());
// Optional: Use escape hatch to retry revocation of globalSignOutError.getAccessToken().
}
RevokeTokenError revokeTokenError = partialSignOutResult.getRevokeTokenError();
if (revokeTokenError != null) {
Log.e("AuthQuickStart", "RevokeToken Error", revokeTokenError.getException());
// Optional: Use escape hatch to retry revocation of revokeTokenError.getRefreshToken().
}
} else if (signOutResult instanceof AWSCognitoAuthSignOutResult.FailedSignOut) {
AWSCognitoAuthSignOutResult.FailedSignOut failedSignOutResult =
(AWSCognitoAuthSignOutResult.FailedSignOut) signOutResult;
// Sign Out failed with an exception, leaving the user signed in.
Log.e("AuthQuickStart", "Sign out Failed", failedSignOutResult.getException());
}
});
Amplify.Auth.signOut { signOutResult ->
when(signOutResult) {
is AWSCognitoAuthSignOutResult.CompleteSignOut -> {
// Sign Out completed fully and without errors.
Log.i("AuthQuickStart", "Signed out successfully")
}
is AWSCognitoAuthSignOutResult.PartialSignOut -> {
// Sign Out completed with some errors. User is signed out of the device.
signOutResult.hostedUIError?.let {
Log.e("AuthQuickStart", "HostedUI Error", it.exception)
// Optional: Re-launch it.url in a Custom tab to clear Cognito web session.
}
signOutResult.globalSignOutError?.let {
Log.e("AuthQuickStart", "GlobalSignOut Error", it.exception)
// Optional: Use escape hatch to retry revocation of it.accessToken.
}
signOutResult.revokeTokenError?.let {
Log.e("AuthQuickStart", "RevokeToken Error", it.exception)
// Optional: Use escape hatch to retry revocation of it.refreshToken.
}
}
is AWSCognitoAuthSignOutResult.FailedSignOut -> {
// Sign Out failed with an exception, leaving the user signed in.
Log.e("AuthQuickStart", "Sign out Failed", signOutResult.exception)
}
}
}
val signOutResult = Amplify.Auth.signOut()
when(signOutResult) {
is AWSCognitoAuthSignOutResult.CompleteSignOut -> {
// Sign Out completed fully and without errors.
Log.i("AuthQuickStart", "Signed out successfully")
}
is AWSCognitoAuthSignOutResult.PartialSignOut -> {
// Sign Out completed with some errors. User is signed out of the device.
signOutResult.hostedUIError?.let {
Log.e("AuthQuickStart", "HostedUI Error", it.exception)
// Optional: Re-launch it.url in a Custom tab to clear Cognito web session.
}
signOutResult.globalSignOutError?.let {
Log.e("AuthQuickStart", "GlobalSignOut Error", it.exception)
// Optional: Use escape hatch to retry revocation of it.accessToken.
}
signOutResult.revokeTokenError?.let {
Log.e("AuthQuickStart", "RevokeToken Error", it.exception)
// Optional: Use escape hatch to retry revocation of it.refreshToken.
}
}
is AWSCognitoAuthSignOutResult.FailedSignOut -> {
// Sign Out failed with an exception, leaving the user signed in.
Log.e("AuthQuickStart", "Sign out Failed", signOutResult.exception)
}
}
RxAmplify.Auth.signOut()
.subscribe(signOutResult -> {
if (signOutResult instanceof AWSCognitoAuthSignOutResult.CompleteSignOut) {
// Sign Out completed fully and without errors.
Log.i("AuthQuickStart", "Signed out successfully");
} else if (signOutResult instanceof AWSCognitoAuthSignOutResult.PartialSignOut) {
// Sign Out completed with some errors. User is signed out of the device.
AWSCognitoAuthSignOutResult.PartialSignOut partialSignOutResult =
(AWSCognitoAuthSignOutResult.PartialSignOut) signOutResult;
HostedUIError hostedUIError = partialSignOutResult.getHostedUIError();
if (hostedUIError != null) {
Log.e("AuthQuickStart", "HostedUI Error", hostedUIError.getException());
// Optional: Re-launch hostedUIError.getUrl() in a Custom tab to clear Cognito web session.
}
GlobalSignOutError globalSignOutError = partialSignOutResult.getGlobalSignOutError();
if (globalSignOutError != null) {
Log.e("AuthQuickStart", "GlobalSignOut Error", globalSignOutError.getException());
// Optional: Use escape hatch to retry revocation of globalSignOutError.getAccessToken().
}
RevokeTokenError revokeTokenError = partialSignOutResult.getRevokeTokenError();
if (revokeTokenError != null) {
Log.e("AuthQuickStart", "RevokeToken Error", revokeTokenError.getException());
// Optional: Use escape hatch to retry revocation of revokeTokenError.getRefreshToken().
}
} else if (signOutResult instanceof AWSCognitoAuthSignOutResult.FailedSignOut) {
AWSCognitoAuthSignOutResult.FailedSignOut failedSignOutResult =
(AWSCognitoAuthSignOutResult.FailedSignOut) signOutResult;
// Sign Out failed with an exception, leaving the user signed in.
Log.e("AuthQuickStart", "Sign out Failed", failedSignOutResult.getException());
}
});

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).

AuthSignOutOptions options = AuthSignOutOptions.builder()
.globalSignOut(true)
.build();
Amplify.Auth.signOut(options, signOutResult -> {
if (signOutResult instanceof AWSCognitoAuthSignOutResult.CompleteSignOut) {
// handle successful sign out
} else if (signOutResult instanceof AWSCognitoAuthSignOutResult.PartialSignOut) {
// handle partial sign out
} else if (signOutResult instanceof AWSCognitoAuthSignOutResult.FailedSignOut) {
// handle failed sign out
}
});
val options = AuthSignOutOptions.builder()
.globalSignOut(true)
.build()
Amplify.Auth.signOut(options) { signOutResult ->
when(signOutResult) {
is AWSCognitoAuthSignOutResult.CompleteSignOut -> {
// handle successful sign out
}
is AWSCognitoAuthSignOutResult.PartialSignOut -> {
// handle partial sign out
}
is AWSCognitoAuthSignOutResult.FailedSignOut -> {
// handle failed sign out
}
}
}
val options = AuthSignOutOptions.builder()
.globalSignOut(true)
.build()
val signOutResult = Amplify.Auth.signOut(options)
when(signOutResult) {
is AWSCognitoAuthSignOutResult.CompleteSignOut -> {
// handle successful sign out
}
is AWSCognitoAuthSignOutResult.PartialSignOut -> {
// handle partial sign out
}
is AWSCognitoAuthSignOutResult.FailedSignOut -> {
// handle failed sign out
}
}
AuthSignOutOptions options = AuthSignOutOptions.builder()
.globalSignOut(true)
.build();
RxAmplify.Auth.signOut(options)
.subscribe(signOutResult -> {
if (signOutResult instanceof AWSCognitoAuthSignOutResult.CompleteSignOut) {
// handle successful sign out
} else if (signOutResult instanceof AWSCognitoAuthSignOutResult.PartialSignOut) {
// handle partial sign out
} else if (signOutResult instanceof AWSCognitoAuthSignOutResult.FailedSignOut) {
// handle failed sign out
}
});