cookiesamazon-cognitonext-auth

AWS Cognito Hosted UI Login - How to "delete AWS' cookie or Log the user out" from the Hosted UI post-login?


I have a NextJS application that is using AWS Cognito for the User Authentication system. We are using AuthJS@5 to integrate with AWS Cognito. After clicking sign-in, the user gets redirected to AWS Managed Login page, where they will put their credentials and logs in, afterwards they will be redirected to our application and an authenticated session ID is now available for them independent of their AWS access/refresh tokens.

It works well!

But the annoying part is that when I log my user out from my application, it only logs them in my application. Their session or cookies are still logged in at the AWS Managed Login page. I have 2 concerns:

  1. Even if they logs out in my application, they are still logged in the AWS managed login page which sounds like a security hole.
  2. Testing or Switching another user is annoying because after logging out and logging in, the AWS managed login automatically signs the previously logged in user to my application.

Attempt to solve

I tried deleting the cookie cognito from my application once the user get's authenticated.

Because the AWS Cognito's cognito cookie definition is as follows:

cognito cookie definition

And by AWS docs:

A cognito session cookie that preserves successful sign-in attempts for an hour.

But this did not work.

So, is there a way to allow the following possible:

  1. Delete the user cookies OR log them out immediately in the AWS on the managed login page after logging in and after they got redirected to my app?
  2. If they logs out of my application, log them out of the AWS managed login page.

I hope anyone can help.

Thanks!


Solution

  • You can log the user out of their Cognito session by using the logout endpoint. You can redirect the user to this URL after logging them out of your app.