@aws-amplify/auth
Version:
Auth category of aws-amplify
40 lines (33 loc) • 1.4 kB
text/typescript
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { CognitoUserPoolConfig } from '@aws-amplify/core';
import { OpenAuthSessionResult } from '../../../../utils/types';
import { DefaultOAuthStore } from '../../utils/signInWithRedirectStore';
import { TokenOrchestrator } from '../../tokenProvider';
import { completeOAuthSignOut } from './completeOAuthSignOut';
import { oAuthSignOutRedirect } from './oAuthSignOutRedirect';
export const handleOAuthSignOut = async (
cognitoConfig: CognitoUserPoolConfig,
store: DefaultOAuthStore,
// No-op here as it's only used in the non-native implementation
tokenOrchestrator: TokenOrchestrator,
redirectUrl: string | undefined,
): Promise<void | OpenAuthSessionResult> => {
const { isOAuthSignIn, preferPrivateSession } = await store.loadOAuthSignIn();
if (isOAuthSignIn) {
const result = await oAuthSignOutRedirect(
cognitoConfig,
preferPrivateSession,
redirectUrl,
);
// If this was a private session, clear data and tokens regardless of what happened with logout
// endpoint. Otherwise, only do so if the logout endpoint was succesfully visited.
const shouldCompleteSignOut =
preferPrivateSession || result?.type === 'success';
if (shouldCompleteSignOut) {
await completeOAuthSignOut(store);
}
return result;
}
return completeOAuthSignOut(store);
};