aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.42k stars 2.12k forks source link

Several users are unable to log in due to the error "Unable to get user session following successful sign-in." #13940

Open k1350 opened 2 days ago

k1350 commented 2 days ago

Before opening, please confirm:

JavaScript Framework

Next.js

Amplify APIs

Authentication

Amplify Version

v6

Amplify Categories

auth

Backend

CDK

Environment information

``` System: OS: macOS 14.6.1 CPU: (10) arm64 Apple M2 Pro Memory: 572.09 MB / 32.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 20.14.0 - ~/.nodenv/versions/20.14.0/bin/node npm: 10.7.0 - ~/.nodenv/versions/20.14.0/bin/npm pnpm: 9.4.0 - ~/.nodenv/versions/20.14.0/bin/pnpm Browsers: Chrome: 129.0.6668.101 Safari: 17.6 Safari Technology Preview: 18.0 npmPackages: @aws-amplify/adapter-nextjs: ^1.2.22 => 1.2.22 @dnd-kit/core: ^6.1.0 => 6.1.0 @dnd-kit/sortable: ^8.0.0 => 8.0.0 @dnd-kit/utilities: ^3.2.2 => 3.2.2 @floating-ui/react: ^0.26.25 => 0.26.25 @formatjs/intl-localematcher: ^0.5.5 => 0.5.5 @hookform/resolvers: ^3.9.0 => 3.9.0 @radix-ui/react-dialog: ^1.1.2 => 1.1.2 @radix-ui/react-toast: ^1.2.2 => 1.2.2 @radix-ui/react-visually-hidden: ^1.1.0 => 1.1.0 @react-hookz/web: ^24.0.4 => 24.0.4 @storybook/react: ^8.3.5 => 8.3.5 @storybook/test: ^8.3.5 => 8.3.5 @t3-oss/env-core: ^0.11.1 => 0.11.1 @tailwindcss/container-queries: ^0.1.1 => 0.1.1 @tiptap/core: 2.8.0 => 2.8.0 @tiptap/extension-bold: 2.8.0 => 2.8.0 @tiptap/extension-bubble-menu: 2.8.0 => 2.8.0 @tiptap/extension-document: 2.8.0 => 2.8.0 @tiptap/extension-dropcursor: 2.8.0 => 2.8.0 @tiptap/extension-floating-menu: 2.8.0 => 2.8.0 @tiptap/extension-gapcursor: 2.8.0 => 2.8.0 @tiptap/extension-hard-break: 2.8.0 => 2.8.0 @tiptap/extension-heading: 2.8.0 => 2.8.0 @tiptap/extension-history: 2.8.0 => 2.8.0 @tiptap/extension-image: 2.8.0 => 2.8.0 @tiptap/extension-link: 2.8.0 => 2.8.0 @tiptap/extension-paragraph: 2.8.0 => 2.8.0 @tiptap/extension-placeholder: 2.8.0 => 2.8.0 @tiptap/extension-text: 2.8.0 => 2.8.0 @tiptap/extension-youtube: 2.8.0 => 2.8.0 @tiptap/pm: 2.8.0 => 2.8.0 @tiptap/react: 2.8.0 => 2.8.0 @types/crypto-js: ^4.2.2 => 4.2.2 @types/lodash: ^4.17.10 => 4.17.10 @types/negotiator: ^0.6.3 => 0.6.3 @types/react: ^18.3.11 => 18.3.11 @types/react-dom: ^18.3.1 => 18.3.1 @urql/core: ^5.0.6 => 5.0.6 @urql/devtools: ^2.0.3 => 2.0.3 @urql/exchange-auth: ^2.2.0 => 2.2.0 autolinker: ^4.0.0 => 4.0.0 autoprefixer: ^10.4.20 => 10.4.20 aws-amplify: ^6.6.5 => 6.6.5 classnames: ^2.5.1 => 2.5.1 crypto-js: ^4.2.0 => 4.2.0 dayjs: ^1.11.13 => 1.11.13 eslint-plugin-n: ^17.11.1 => 17.11.1 eslint-plugin-storybook: ^0.9.0 => 0.9.0 eslint-plugin-tailwindcss: ^3.17.5 => 3.17.5 firebase: ^10.11.1 => 10.11.1 graphql: ^16.9.0 => 16.9.0 graphql-tag: ^2.12.6 => 2.12.6 isbot: ^5.1.17 => 5.1.17 lodash: ^4.17.21 => 4.17.21 mockdate: ^3.0.5 => 3.0.5 negotiator: ^0.6.3 => 0.6.3 next: 14.2.13 => 14.2.13 next-intl: ^3.21.1 => 3.21.1 nuqs: ^1.20.0 => 1.20.0 p-retry: ^6.2.0 => 6.2.0 postcss: ^8.4.47 => 8.4.47 prettier-plugin-tailwindcss: ^0.6.8 => 0.6.8 react: ^18.3.1 => 18.3.1 react-dom: ^18.3.1 => 18.3.1 react-hook-form: ^7.53.0 => 7.53.0 react-infinite-scroll-hook: ^5.0.1 => 5.0.1 rimraf: ^6.0.1 => 6.0.1 swr: ^2.2.5 => 2.2.5 tailwindcss: ^3.4.13 => 3.4.13 tailwindcss-animate: ^1.0.7 => 1.0.7 typescript: ^5.6.3 => 5.6.3 vitest: ^2.1.3 => 2.1.3 wonka: ^6.3.4 => 6.3.4 zod: ^3.23.8 => 3.23.8 npmGlobalPackages: corepack: 0.28.1 firebase-tools: 13.11.4 npm: 10.7.0 vercel: 37.3.0 ```

Describe the bug

Most users are able to log in without any issues, but some users have reported that they are encountering the following error when attempting to log in:

UnexpectedSignInInterruptionException: Unable to get user session following successful sign-in.

After interviewing an affected user, we found that he can log in using Firefox, but he is unable to log in with Google Chrome, no matter how many times he trys. Clearing caches and cookies did not resolve the issue.

We have investigated this thoroughly but have been unable to reproduce the error, and the cause remains unclear. We also reviewed previously raised issues but did not find any information that could help resolve the problem.

What kind of situations can trigger this error? We would like to know how to resolve it for users who are encountering this error consistently.

Thank you.

Expected behavior

The authentication process should successfully complete without any errors.

Reproduction steps

As the issue has not been reproducible, we're unable to provide specific steps that consistently trigger the error. Below are the general steps a user would follow.

  1. Navigate to the sign-in page of our application.
  2. Enter valid username and password.
  3. Click the "Log in" button.

Code Snippet

// Put your code below this line.

Log output

``` // Put your logs below this line ```

aws-exports.js

No response

Manual configuration

import type { ResourcesConfig } from 'aws-amplify';
import { Amplify } from 'aws-amplify';
import { cognitoUserPoolsTokenProvider } from 'aws-amplify/auth/cognito';
import { CookieStorage } from 'aws-amplify/utils';

const amplifyConfig: ResourcesConfig = {
  Auth: {
    Cognito: {
      userPoolId: "xxx",
      userPoolClientId: "xxx",
      identityPoolId: "xxx",
      allowGuestAccess: true,
    },
  },
};

Amplify.configure(amplifyConfig, { ssr: true });

cognitoUserPoolsTokenProvider.setKeyValueStorage(
  new CookieStorage({
    domain: "xxx",
    secure: true,
    path: '/',
    sameSite: 'lax',
    expires: 365,
  }),
);

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

cwomack commented 2 days ago

@k1350, thanks for opening this issue and sorry to hearing your users are experiencing this.

k1350 commented 1 day ago

@cwomack Thank you for your reply.

Can you share any detailed logs or network requests for when this happens.

The logs and network requests have not been captured.

Do you know any details around the version of Chrome these users are on?

OS: Windows 10 Browser: Chrome 129 (129.0.0.0) Full User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36

Is your domain value within the CookieStorage a subdomain or something different?

If we set the domain of our application as example.com, the domain for CookieStorage is also example.com. We are sharing cookies with another application running under the domain sub.example.com.

For the users you interviewed... do you know if they are disabling cookie storage in Chrome specifically?

I have been informed that cookies are enabled.


This is additional information regarding the issue.

In our application, we added a process that signout and redirects them to the top page when a NotAuthorizedException or UserNotFoundException occurs during the execution of fetchAuthSession yesterday. As a result, the user encountering this issue have reported that the top page reloads repeatedly.

So I guess it comes down to this.

Sign-in is failing with the error: UnexpectedSignInInterruptionException: Unable to get user session following successful sign-in.

However, on the other hand, a NotAuthorizedException or UserNotFoundException is occurring during the execution of fetchAuthSession, and it seems that the sign-out process is not working correctly in this case.

The NotAuthorizedException or UserNotFoundException errors we have observed is:

We know that NotAuthorizedException: Token is inactive occurs when a user is deactivated. However, we have not been able to reproduce the othe errors, and it is unclear under what circumstances they occur.

k1350 commented 1 day ago

@cwomack Additional information: A user who encountered the problem reported that sign-in worked properly in Chrome's Incognito Mode. However, the issue still persists when not using Incognito Mode.