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.

When using withAuthenticator, users are sometimes logged out when opening the app while offline

See original GitHub issue

Before opening, please confirm:

JavaScript Framework

React

Amplify APIs

Authentication, DataStore

Amplify Categories

auth

Environment information

  System:
    OS: Linux 5.18 Arch Linux
    CPU: (16) x64 AMD Ryzen 7 3700X 8-Core Processor
    Memory: 6.91 GB / 31.26 GB
    Container: Yes
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 16.13.2 - ~/.nvm/versions/node/v16.13.2/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 8.1.2 - ~/.nvm/versions/node/v16.13.2/bin/npm
  Browsers:
    Firefox: 106.0.2
  npmPackages:
    @aws-amplify/ui-react: ^3.5.9 => 3.5.9
    @aws-amplify/ui-react-internal:  undefined ()
    @aws-amplify/ui-react-legacy:  undefined ()
    @testing-library/jest-dom: ^5.16.5 => 5.16.5
    @testing-library/react: ^13.4.0 => 13.4.0
    @testing-library/user-event: ^13.5.0 => 13.5.0
    react: ^18.2.0 => 18.2.0 (18.1.0)
    react-dom: ^18.2.0 => 18.2.0
    react-scripts: 5.0.1 => 5.0.1
    web-vitals: ^2.1.4 => 2.1.4
    workbox-background-sync: ^6.5.4 => 6.5.4
    workbox-broadcast-update: ^6.5.4 => 6.5.4
    workbox-cacheable-response: ^6.5.4 => 6.5.4
    workbox-core: ^6.5.4 => 6.5.4
    workbox-expiration: ^6.5.4 => 6.5.4
    workbox-google-analytics: ^6.5.4 => 6.5.4
    workbox-navigation-preload: ^6.5.4 => 6.5.4
    workbox-precaching: ^6.5.4 => 6.5.4
    workbox-range-requests: ^6.5.4 => 6.5.4
    workbox-routing: ^6.5.4 => 6.5.4
    workbox-strategies: ^6.5.4 => 6.5.4
    workbox-streams: ^6.5.4 => 6.5.4
  npmGlobalPackages:
    @aws-amplify/cli: 10.4.0
    @ionic/cli: 6.20.3
    cordova: 11.0.0
    corepack: 0.10.0
    create-react-native-app: 3.8.0
    deadfile: 2.0.1
    native-run: 1.7.1
    npm: 8.1.2
    react-js-to-ts: 1.4.0
    ts-node: 10.9.1
    typescript: 4.8.2


Describe the bug

If a React app is registered with a service worker and the app is opened while offline the page will still load.

When using withAuthenticator to manage logins, the user is sometimes logged out and unable to access any offline data.

When used with DataStore this means that users are unable to access data stored locally on their device while offline.

Expected behavior

The user should be kept logged in when the app is opened while offline.

Reproduction steps

npx create-react-app auth-issue --template cra-template-pwa
cd auth-issue
npm install aws-amplify
npm install @aws-amplify/ui-react
amplify init # use defaults
amplify add auth # use defaults
amplify add hosting # use defaults
amplify publish

amplify auth console

Add a test user to Cognito.

Load the example up on Chrome on mobile and click the 3 dots at the top right > Install app Go offline by enabling airplane mode. Close the app fully. Reopen the app. The user may be logged out.

This seems more likely to happen if it is done some time after the app was last opened.

I haven’t been able to recreate the issue on desktop yet.

Code Snippet

src/App.js

import React from "react";
import { withAuthenticator } from "@aws-amplify/ui-react";
import Amplify from "aws-amplify";

const config = require("../src/aws-exports");
Amplify.configure({
  ...config.default,
});

function App() {
  return <div>hello</div>;
}

export default withAuthenticator(App);

Log output

// Put your logs below this line


aws-exports.js

const awsmobile = {
    "aws_project_region": "eu-west-1",
    "aws_cognito_identity_pool_id": "eu-west-1:f675981e-9a3e-437b-9787-3a82a8b6e583",
    "aws_cognito_region": "eu-west-1",
    "aws_user_pools_id": "eu-west-1_22aenN7I6",
    "aws_user_pools_web_client_id": "41dfl18nl8t1o53b2ojb8626ed",
    "oauth": {},
    "aws_cognito_username_attributes": [],
    "aws_cognito_social_providers": [],
    "aws_cognito_signup_attributes": [
        "EMAIL"
    ],
    "aws_cognito_mfa_configuration": "OFF",
    "aws_cognito_mfa_types": [
        "SMS"
    ],
    "aws_cognito_password_protection_settings": {
        "passwordPolicyMinLength": 8,
        "passwordPolicyCharacters": []
    },
    "aws_cognito_verification_mechanisms": [
        "EMAIL"
    ]
};


export default awsmobile;

Manual configuration

No response

Additional configuration

No response

Mobile Device

Xiaomi Mi 9T

Mobile Operating System

Android 11

Mobile Browser

Chrome

Mobile Browser Version

106.0.5249.126

Additional information and screenshots

package.json

  "name": "auth-issue",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@aws-amplify/ui-react": "^3.5.10",
    "@testing-library/jest-dom": "^5.16.5",
    "@testing-library/react": "^13.4.0",
    "@testing-library/user-event": "^13.5.0",
    "aws-amplify": "^4.3.42",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-scripts": "5.0.1",
    "web-vitals": "^2.1.4",
    "workbox-background-sync": "^6.5.4",
    "workbox-broadcast-update": "^6.5.4",
    "workbox-cacheable-response": "^6.5.4",
    "workbox-core": "^6.5.4",
    "workbox-expiration": "^6.5.4",
    "workbox-google-analytics": "^6.5.4",
    "workbox-navigation-preload": "^6.5.4",
    "workbox-precaching": "^6.5.4",
    "workbox-range-requests": "^6.5.4",
    "workbox-routing": "^6.5.4",
    "workbox-strategies": "^6.5.4",
    "workbox-streams": "^6.5.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "preserve:static": "npm run build",
    "serve:static": "npx serve ./build  -p 3000"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}```

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
duckbytescommented, Nov 5, 2022

Figured that was the case. I think I can close this as solved now.

Thanks for your help.

1reaction
ncarvajalccommented, Nov 4, 2022

I could actually visualize that random sign out this morning, a few hours had passed since log in. I’ll take a deeper look into it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Common questions about the Microsoft Authenticator app
A: Users can send logs to customer support and get the Incident ID with these steps: Open Microsoft Authenticator. Tap Send feedback in...
Read more >
Solving offline logout problem - Medium
The easiest solution for offline log out would be to disable ability to logout when user is offline. However we want to improve...
Read more >
Creating offline web apps with AWS Amplify DataStore
This simple tutorial shows you how to create a serverless backend using AWS Amplify DataStore with only a few lines of code.
Read more >
Authenticator - React Native - AWS Amplify Docs
withAuthenticator component renders your App component after a successful user signed in, and it prevents non-sign-in users to interact with your app. In...
Read more >
Yubico Login for Windows Configuration Guide
Note: Local accounts will not be accessible by Windows Remote Desktop (RDP), but may still be accessible through other remote access software ...
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