When using withAuthenticator, users are sometimes logged out when opening the app while offline
See original GitHub issueBefore opening, please confirm:
- I have searched for duplicate or closed issues and discussions.
- I have read the guide for submitting bug reports.
- I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
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:
- Created a year ago
- Comments:10 (5 by maintainers)
Figured that was the case. I think I can close this as solved now.
Thanks for your help.
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.