question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Auth.signOut() doesn't redirect to the Cognito Hosted UI logout endpoint

See original GitHub issue

This is an OAuth scenario with the Cognito hosted UI

See sample code below. When clicking the signOut button I see that cookies get cleared, but the browser is not redirected to the /logout endpoint which I think it should be doing. Because it doesn’t do that, the user remains logged in at Cognito.

import React, { useState, useEffect } from 'react';
import Amplify, { Auth, Hub } from 'aws-amplify';

Amplify.configure({
  Auth: {
    region: 'us-east-1',
    userPoolId: 'xxx',
    userPoolWebClientId: 'xxx',
    cookieStorage: {
      domain: 'xxx',
    },
    oauth: {
      domain: 'xxx.us-east-1.amazoncognito.com',
      scope: ['phone', 'email', 'profile', 'openid', 'aws.cognito.signin.user.admin'],
      redirectSignIn: 'xxx/parseauth',
      redirectSignOut: 'xxx/',
      responseType: 'code',
    },
  }
});


function App() {
  const [user, setUser] = useState(null);

  useEffect(() => {
    const subscribeToHub = async () => {
      Hub.listen("auth", ({ payload: { event, data } }) => {
        switch (event) {
          case "signIn":
            setUser(data);
            break;
          case "signOut":
            setUser(null);
            break;
          default:
            break;
        }
      });
    };
    subscribeToHub();
  }, []);

  useEffect(() => {
    Auth.currentAuthenticatedUser()
    .then(setUser)
    .catch(console.error);
  }, []);

  return (
    <div>
      <header>
          {user && <p>Hi {user.username}!!</p>}
          {!user && <p>You are not signed in</p>}
          <button onClick={() => Auth.federatedSignIn()}>Open Hosted UI</button>
          <button onClick={() => Auth.signOut()}>Sign Out</button>
      </header>
    </div>
  );
}

export default App;

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
charleswdukcommented, May 15, 2020

@kennethesguerra Didn’t find a solution. I’m thinking about integrating with Cognito directly, but haven’t investigated whether this will help yet… If anyone finds a solution that works with Amplify, please let me know, as I would much rather stick with it!

1reaction
kennethesguerracommented, May 15, 2020

I’m struggling with this one too…I’ve configured Amplify to use cookie storage for auth, but using Auth.signOut() doesn’t work properly. Clicking on Auth.federatedSignIn() signs users straight in again because the cookies set by cognito remain.

I tried adding the cookie @ottokruse suggested, but this did not work.

Does anyone have a working implementation using Amplify, Cognito Hosted UI and cookie storage?

The Cognito Hosted UI seems to have disappeared from v2 of the JS Amplify docs…I hope it’s still being supported.

Any help much appreciated - thanks!

@charleswduk same situation also. Have you already found the workaround on this? This has been an issue a year ago though in amplify https://github.com/aws-amplify/amplify-js/issues/3435

Read more comments on GitHub >

github_iconTop Results From Across the Web

Logout endpoint - Amazon Cognito - AWS Documentation
The /logout endpoint signs the user out and redirects either to an authorized sign-out URL for your app client, or to the /login...
Read more >
Cognito logout does not work as documented - Stack Overflow
This redirect happens whenever logout_uri parameter doesn't match exactly what's listed among Sign out URL(s) in AWS Cognito User Pools App ...
Read more >
cognito hosted ui logout failing with - AWS re:Post
Your call to the Cognito /logout endpoint shouldn't be an XHR request -- the browser needs to be redirected to there. Cognito will...
Read more >
Logout - Auth0
Learn how to redirect users after logout. You can log a user out of the Auth0 session and (optionally) from the identity provider ......
Read more >
Cognito Authentication for your SvelteKit app - Roberto Huertas
The Sign Out url is the final url to be redirected to once we've signed out from Cognito. Finally, for the Cognito Hosted...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found