Amplify global SignOut is not logging out for all the connected apps with Cognito Federated Auth

63 Views Asked by At

We have created an AWS Cognito Pool with Azure Federated SAML. I have four applications developed using Amplify with React JS as FrontEnd and used the same Cognito Pool for all.

const cognitoConf = {
    "aws_project_region": "us-east-1",
    "aws_cognito_region": "us-east-1",
    "aws_user_pools_id": "us-east-<POOL_ID>",
    "aws_user_pools_web_client_id": "<WEB_CLIENT_ID>",
    "oauth": {
        "domain": "<MY_APPLICATION_POOL>.auth.us-east-1.amazoncognito.com",
        "scope": [
            "email",
            "openid",
            "profile"
        ],
        "redirectSignIn": "https://dev.<MY_AMPLIFY_HOST>.amplifyapp.com",
        "redirectSignOut": "https://dev.<MY_AMPLIFY_HOST>.amplifyapp.com",
        "responseType": "code"
    }
};

export default cognitoConf

In every app, we have used the same config file, and below session check mechanism -

import { Amplify } from 'aws-amplify';
import cognitoConf from './cognito-conf';
import { fetchAuthSession, signInWithRedirect, signOut } from "aws-amplify/auth";
Amplify.configure(cognitoConf);

function App() {
    async function checkAuthSession() {
        const fetchSessionResult = await fetchAuthSession();
        if (fetchSessionResult?.tokens?.idToken === undefined) {
            await signInWithRedirect();
        }
    }

    checkAuthSession();

    return (
            <> ... </>
    );
}

And in the Header panel, we have added signout functionality,

import { signOut } from "aws-amplify/auth";

function HeaderPanel() {
    const handleSignOut = async () => {
        try {
            await signOut({ global: true });
        } catch (error) {
            console.error('Error signing out:', error);
        }
    };

    return (
        <Button variant="contained" onClick={handleSignOut}>SignOut</Button>
    )
}

Login functionality is now working correctly, but the issue is that when we sign out from one account, that does not affect other applications, not signing out, even when refreshing the other application, does not prompt the login page again. Sign-out is happening only in that application where we hit the SignOut button. How to solve this issue? Please help.

0

There are 0 best solutions below