From 0fef619d063f5d73180a0cf771fd1cd028a6023c Mon Sep 17 00:00:00 2001 From: Christian Fehmer Date: Tue, 13 Feb 2024 19:03:50 +0100 Subject: [PATCH] refactor: null-safe usage of Auth.currentUser (fehmer) (#5048) * fix: error on leaderboard when no user is present * refactor simple popups * popups, commandline * fixes? * more * more * review comments --------- Co-authored-by: Jack --- frontend/package-lock.json | 476 +++++++++--------- frontend/package.json | 2 +- frontend/src/ts/ape/adapters/axios-adapter.ts | 7 +- frontend/src/ts/commandline/index.ts | 4 +- .../commandline/lists/custom-themes-list.ts | 6 +- frontend/src/ts/commandline/lists/presets.ts | 4 +- .../src/ts/commandline/lists/quote-length.ts | 4 +- .../src/ts/commandline/lists/random-theme.ts | 4 +- frontend/src/ts/commandline/lists/tags.ts | 4 +- frontend/src/ts/config.ts | 6 +- .../src/ts/controllers/account-controller.ts | 10 +- .../src/ts/controllers/route-controller.ts | 4 +- frontend/src/ts/db.ts | 16 +- frontend/src/ts/elements/account-button.ts | 4 +- frontend/src/ts/elements/alerts.ts | 6 +- frontend/src/ts/elements/leaderboards.ts | 8 +- frontend/src/ts/elements/modes-notice.ts | 4 +- frontend/src/ts/firebase.ts | 15 +- frontend/src/ts/pages/settings.ts | 14 +- frontend/src/ts/popups/quote-search-popup.ts | 8 +- frontend/src/ts/popups/simple-popups.ts | 71 +-- frontend/src/ts/settings/theme-picker.ts | 6 +- frontend/src/ts/test/result.ts | 8 +- frontend/src/ts/test/test-logic.ts | 8 +- frontend/src/ts/test/test-ui.ts | 6 +- 25 files changed, 345 insertions(+), 360 deletions(-) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 14f21e815..e31ea26bc 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -18,7 +18,7 @@ "crypto-browserify": "3.12.0", "damerau-levenshtein": "1.0.8", "date-fns": "2.28.0", - "firebase": "10.3.0", + "firebase": "10.8.0", "hangul-js": "0.2.6", "howler": "2.2.3", "html2canvas": "1.4.1", @@ -1889,15 +1889,23 @@ "node": "^12.22.0 || ^14.17.0 || >=16.0.0" } }, + "node_modules/@fastify/busboy": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.1.0.tgz", + "integrity": "sha512-+KpH+QxZU7O4675t3mnkQKcZZg56u+K/Ct2K+N2AZYNVK8kyeo/bI18tI8aPm3tvNNRyTWfj6s5tnGNlcbQRsA==", + "engines": { + "node": ">=14" + } + }, "node_modules/@firebase/analytics": { - "version": "0.10.0", - "resolved": "https://registry.npmjs.org/@firebase/analytics/-/analytics-0.10.0.tgz", - "integrity": "sha512-Locv8gAqx0e+GX/0SI3dzmBY5e9kjVDtD+3zCFLJ0tH2hJwuCAiL+5WkHuxKj92rqQj/rvkBUCfA1ewlX2hehg==", + "version": "0.10.1", + "resolved": "https://registry.npmjs.org/@firebase/analytics/-/analytics-0.10.1.tgz", + "integrity": "sha512-5mnH1aQa99J5lZMJwTNzIoRc4yGXHf+fOn+EoEWhCDA3XGPweGHcylCbqq+G1wVJmfILL57fohDMa8ftMZ+44g==", "dependencies": { - "@firebase/component": "0.6.4", - "@firebase/installations": "0.6.4", + "@firebase/component": "0.6.5", + "@firebase/installations": "0.6.5", "@firebase/logger": "0.4.0", - "@firebase/util": "1.9.3", + "@firebase/util": "1.9.4", "tslib": "^2.1.0" }, "peerDependencies": { @@ -1905,14 +1913,14 @@ } }, "node_modules/@firebase/analytics-compat": { - "version": "0.2.6", - "resolved": "https://registry.npmjs.org/@firebase/analytics-compat/-/analytics-compat-0.2.6.tgz", - "integrity": "sha512-4MqpVLFkGK7NJf/5wPEEP7ePBJatwYpyjgJ+wQHQGHfzaCDgntOnl9rL2vbVGGKCnRqWtZDIWhctB86UWXaX2Q==", + "version": "0.2.7", + "resolved": "https://registry.npmjs.org/@firebase/analytics-compat/-/analytics-compat-0.2.7.tgz", + "integrity": "sha512-17VCly4P0VFBDqaaal7m1nhyYQwsygtaTpSsnc51sFPRrr9XIYtnD8ficon9fneEGEoJQ2g7OtASvhwX9EbK8g==", "dependencies": { - "@firebase/analytics": "0.10.0", + "@firebase/analytics": "0.10.1", "@firebase/analytics-types": "0.8.0", - "@firebase/component": "0.6.4", - "@firebase/util": "1.9.3", + "@firebase/component": "0.6.5", + "@firebase/util": "1.9.4", "tslib": "^2.1.0" }, "peerDependencies": { @@ -1925,25 +1933,25 @@ "integrity": "sha512-iRP+QKI2+oz3UAh4nPEq14CsEjrjD6a5+fuypjScisAh9kXKFvdJOZJDwk7kikLvWVLGEs9+kIUS4LPQV7VZVw==" }, "node_modules/@firebase/app": { - "version": "0.9.17", - "resolved": "https://registry.npmjs.org/@firebase/app/-/app-0.9.17.tgz", - "integrity": "sha512-jBEGJ3km90M6sAc2O0baScDs0JAD1gGvZo7AniNVg06kvmaj+KEfGOaASwhlHNvIE2sYrOBqgobZADgaiYp5KQ==", + "version": "0.9.27", + "resolved": "https://registry.npmjs.org/@firebase/app/-/app-0.9.27.tgz", + "integrity": "sha512-p2Dvl1ge4kRsyK5+wWcmdAIE9MSwZ0pDKAYB51LZgZuz6wciUZk4E1yAEdkfQlRxuHehn+Ol9WP5Qk2XQZiHGg==", "dependencies": { - "@firebase/component": "0.6.4", + "@firebase/component": "0.6.5", "@firebase/logger": "0.4.0", - "@firebase/util": "1.9.3", + "@firebase/util": "1.9.4", "idb": "7.1.1", "tslib": "^2.1.0" } }, "node_modules/@firebase/app-check": { - "version": "0.8.0", - "resolved": "https://registry.npmjs.org/@firebase/app-check/-/app-check-0.8.0.tgz", - "integrity": "sha512-dRDnhkcaC2FspMiRK/Vbp+PfsOAEP6ZElGm9iGFJ9fDqHoPs0HOPn7dwpJ51lCFi1+2/7n5pRPGhqF/F03I97g==", + "version": "0.8.2", + "resolved": "https://registry.npmjs.org/@firebase/app-check/-/app-check-0.8.2.tgz", + "integrity": "sha512-A2B5+ldOguYAeqW1quFN5qNdruSNRrg4W59ag1Eq6QzxuHNIkrE+TrapfrW/z5NYFjCxAYqr/unVCgmk80Dwcg==", "dependencies": { - "@firebase/component": "0.6.4", + "@firebase/component": "0.6.5", "@firebase/logger": "0.4.0", - "@firebase/util": "1.9.3", + "@firebase/util": "1.9.4", "tslib": "^2.1.0" }, "peerDependencies": { @@ -1951,15 +1959,15 @@ } }, "node_modules/@firebase/app-check-compat": { - "version": "0.3.7", - "resolved": "https://registry.npmjs.org/@firebase/app-check-compat/-/app-check-compat-0.3.7.tgz", - "integrity": "sha512-cW682AxsyP1G+Z0/P7pO/WT2CzYlNxoNe5QejVarW2o5ZxeWSSPAiVEwpEpQR/bUlUmdeWThYTMvBWaopdBsqw==", + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/@firebase/app-check-compat/-/app-check-compat-0.3.9.tgz", + "integrity": "sha512-7LxyupQ8XeEHRh72mO+tqm69kHT6KbWi2KtFMGedJ6tNbwzFzojcXESMKN8RpADXbYoQgY3loWMJjMx4r2Zt7w==", "dependencies": { - "@firebase/app-check": "0.8.0", + "@firebase/app-check": "0.8.2", "@firebase/app-check-types": "0.5.0", - "@firebase/component": "0.6.4", + "@firebase/component": "0.6.5", "@firebase/logger": "0.4.0", - "@firebase/util": "1.9.3", + "@firebase/util": "1.9.4", "tslib": "^2.1.0" }, "peerDependencies": { @@ -1977,14 +1985,14 @@ "integrity": "sha512-uwSUj32Mlubybw7tedRzR24RP8M8JUVR3NPiMk3/Z4bCmgEKTlQBwMXrehDAZ2wF+TsBq0SN1c6ema71U/JPyQ==" }, "node_modules/@firebase/app-compat": { - "version": "0.2.17", - "resolved": "https://registry.npmjs.org/@firebase/app-compat/-/app-compat-0.2.17.tgz", - "integrity": "sha512-1vtnLdxe7lXN5jtv5hUpoKsHPvE56YUgelxmpY/OA1JELIH9ATBv/dsbDvSnsiaRkoQz/4F4B3iMma0JdxlIQA==", + "version": "0.2.27", + "resolved": "https://registry.npmjs.org/@firebase/app-compat/-/app-compat-0.2.27.tgz", + "integrity": "sha512-SYlqocfUDKPHR6MSFC8hree0BTiWFu5o8wbf6zFlYXyG41w7TcHp4wJi4H/EL5V6cM4kxwruXTJtqXX/fRAZtw==", "dependencies": { - "@firebase/app": "0.9.17", - "@firebase/component": "0.6.4", + "@firebase/app": "0.9.27", + "@firebase/component": "0.6.5", "@firebase/logger": "0.4.0", - "@firebase/util": "1.9.3", + "@firebase/util": "1.9.4", "tslib": "^2.1.0" } }, @@ -1994,15 +2002,15 @@ "integrity": "sha512-AeweANOIo0Mb8GiYm3xhTEBVCmPwTYAu9Hcd2qSkLuga/6+j9b1Jskl5bpiSQWy9eJ/j5pavxj6eYogmnuzm+Q==" }, "node_modules/@firebase/auth": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/@firebase/auth/-/auth-1.3.0.tgz", - "integrity": "sha512-vjK4CHbY9aWdiVOrKi6mpa8z6uxeaf7LB/MZTHuZOiGHMcUoTGB6TeMbRShyqk1uaMrxhhZ5Ar/dR0965E1qyA==", + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@firebase/auth/-/auth-1.6.0.tgz", + "integrity": "sha512-Qhl35eJTV6BwvuueTPCY6x8kUlYyzALtjp/Ws0X3fw3AnjVVfuVb7oQ3Xh5VPVfMFhaIuUAd1KXwcAuIklkSDw==", "dependencies": { - "@firebase/component": "0.6.4", + "@firebase/component": "0.6.5", "@firebase/logger": "0.4.0", - "@firebase/util": "1.9.3", - "node-fetch": "2.6.7", - "tslib": "^2.1.0" + "@firebase/util": "1.9.4", + "tslib": "^2.1.0", + "undici": "5.26.5" }, "peerDependencies": { "@firebase/app": "0.x", @@ -2015,16 +2023,16 @@ } }, "node_modules/@firebase/auth-compat": { - "version": "0.4.6", - "resolved": "https://registry.npmjs.org/@firebase/auth-compat/-/auth-compat-0.4.6.tgz", - "integrity": "sha512-pKp1d4fSf+yoy1EBjTx9ISxlunqhW0vTICk0ByZ3e+Lp6ZIXThfUy4F1hAJlEafD/arM0oepRiAh7LXS1xn/BA==", + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/@firebase/auth-compat/-/auth-compat-0.5.2.tgz", + "integrity": "sha512-pRgje5BPCNR1vXyvGOVXwOHtv88A2WooXfklI8sV7/jWi03ExFqNfpJT26GUo/oD39NoKJ3Kt6rD5gVvdV7lMw==", "dependencies": { - "@firebase/auth": "1.3.0", + "@firebase/auth": "1.6.0", "@firebase/auth-types": "0.12.0", - "@firebase/component": "0.6.4", - "@firebase/util": "1.9.3", - "node-fetch": "2.6.7", - "tslib": "^2.1.0" + "@firebase/component": "0.6.5", + "@firebase/util": "1.9.4", + "tslib": "^2.1.0", + "undici": "5.26.5" }, "peerDependencies": { "@firebase/app-compat": "0.x" @@ -2045,62 +2053,63 @@ } }, "node_modules/@firebase/component": { - "version": "0.6.4", - "resolved": "https://registry.npmjs.org/@firebase/component/-/component-0.6.4.tgz", - "integrity": "sha512-rLMyrXuO9jcAUCaQXCMjCMUsWrba5fzHlNK24xz5j2W6A/SRmK8mZJ/hn7V0fViLbxC0lPMtrK1eYzk6Fg03jA==", + "version": "0.6.5", + "resolved": "https://registry.npmjs.org/@firebase/component/-/component-0.6.5.tgz", + "integrity": "sha512-2tVDk1ixi12sbDmmfITK8lxSjmcb73BMF6Qwc3U44hN/J1Fi1QY/Hnnb6klFlbB9/G16a3J3d4nXykye2EADTw==", "dependencies": { - "@firebase/util": "1.9.3", + "@firebase/util": "1.9.4", "tslib": "^2.1.0" } }, "node_modules/@firebase/database": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/@firebase/database/-/database-1.0.1.tgz", - "integrity": "sha512-VAhF7gYwunW4Lw/+RQZvW8dlsf2r0YYqV9W0Gi2Mz8+0TGg1mBJWoUtsHfOr8kPJXhcLsC4eP/z3x6L/Fvjk/A==", + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@firebase/database/-/database-1.0.3.tgz", + "integrity": "sha512-9fjqLt9JzL46gw9+NRqsgQEMjgRwfd8XtzcKqG+UYyhVeFCdVRQ0Wp6Dw/dvYHnbH5vNEKzNv36dcB4p+PIAAA==", "dependencies": { + "@firebase/app-check-interop-types": "0.3.0", "@firebase/auth-interop-types": "0.2.1", - "@firebase/component": "0.6.4", + "@firebase/component": "0.6.5", "@firebase/logger": "0.4.0", - "@firebase/util": "1.9.3", + "@firebase/util": "1.9.4", "faye-websocket": "0.11.4", "tslib": "^2.1.0" } }, "node_modules/@firebase/database-compat": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/@firebase/database-compat/-/database-compat-1.0.1.tgz", - "integrity": "sha512-ky82yLIboLxtAIWyW/52a6HLMVTzD2kpZlEilVDok73pNPLjkJYowj8iaIWK5nTy7+6Gxt7d00zfjL6zckGdXQ==", + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@firebase/database-compat/-/database-compat-1.0.3.tgz", + "integrity": "sha512-7tHEOcMbK5jJzHWyphPux4osogH/adWwncxdMxdBpB9g1DNIyY4dcz1oJdlkXGM/i/AjUBesZsd5CuwTRTBNTw==", "dependencies": { - "@firebase/component": "0.6.4", - "@firebase/database": "1.0.1", - "@firebase/database-types": "1.0.0", + "@firebase/component": "0.6.5", + "@firebase/database": "1.0.3", + "@firebase/database-types": "1.0.1", "@firebase/logger": "0.4.0", - "@firebase/util": "1.9.3", + "@firebase/util": "1.9.4", "tslib": "^2.1.0" } }, "node_modules/@firebase/database-types": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@firebase/database-types/-/database-types-1.0.0.tgz", - "integrity": "sha512-SjnXStoE0Q56HcFgNQ+9SsmJc0c8TqGARdI/T44KXy+Ets3r6x/ivhQozT66bMnCEjJRywYoxNurRTMlZF8VNg==", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@firebase/database-types/-/database-types-1.0.1.tgz", + "integrity": "sha512-Tmcmx5XgiI7UVF/4oGg2P3AOTfq3WKEPsm2yf+uXtN7uG/a4WTWhVMrXGYRY2ZUL1xPxv9V33wQRJ+CcrUhVXw==", "dependencies": { "@firebase/app-types": "0.9.0", - "@firebase/util": "1.9.3" + "@firebase/util": "1.9.4" } }, "node_modules/@firebase/firestore": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/@firebase/firestore/-/firestore-4.1.2.tgz", - "integrity": "sha512-PZkXw2yfVcKgVvsd1rohOJ27bJz/p+TccwdraMgE701eDAj5xccGPmCVvMfFq0nz+BmQVuD5wUUVBBRMVCGOfw==", + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/@firebase/firestore/-/firestore-4.4.2.tgz", + "integrity": "sha512-YaX6ypa/RzU6OkxzUQlpSxwhOIWdTraCNz7sMsbaSEjjl/pj/QvX6TqjkdWGzuBYh2S6rz7ErhDO0g39oZZw/g==", "dependencies": { - "@firebase/component": "0.6.4", + "@firebase/component": "0.6.5", "@firebase/logger": "0.4.0", - "@firebase/util": "1.9.3", - "@firebase/webchannel-wrapper": "0.10.2", - "@grpc/grpc-js": "~1.8.17", + "@firebase/util": "1.9.4", + "@firebase/webchannel-wrapper": "0.10.5", + "@grpc/grpc-js": "~1.9.0", "@grpc/proto-loader": "^0.7.8", - "node-fetch": "2.6.7", - "tslib": "^2.1.0" + "tslib": "^2.1.0", + "undici": "5.26.5" }, "engines": { "node": ">=10.10.0" @@ -2110,14 +2119,14 @@ } }, "node_modules/@firebase/firestore-compat": { - "version": "0.3.16", - "resolved": "https://registry.npmjs.org/@firebase/firestore-compat/-/firestore-compat-0.3.16.tgz", - "integrity": "sha512-+UsOsLLtFLIU1fGjFZE6BL3LzEwknkrzv/U3ZcNk/C6cKcThuGBu53yZ6gxW9S7o1GUFiIey86HQi8kwdcAVZA==", + "version": "0.3.25", + "resolved": "https://registry.npmjs.org/@firebase/firestore-compat/-/firestore-compat-0.3.25.tgz", + "integrity": "sha512-+xI7WmsgZCBhMn/+uhDKcg+lsOUJ9FJyt5PGTzkFPbCsozWfeQZ7eVnfPh0rMkUOf0yIQ924RIe04gwvEIbcoQ==", "dependencies": { - "@firebase/component": "0.6.4", - "@firebase/firestore": "4.1.2", + "@firebase/component": "0.6.5", + "@firebase/firestore": "4.4.2", "@firebase/firestore-types": "3.0.0", - "@firebase/util": "1.9.3", + "@firebase/util": "1.9.4", "tslib": "^2.1.0" }, "peerDependencies": { @@ -2134,31 +2143,31 @@ } }, "node_modules/@firebase/functions": { - "version": "0.10.0", - "resolved": "https://registry.npmjs.org/@firebase/functions/-/functions-0.10.0.tgz", - "integrity": "sha512-2U+fMNxTYhtwSpkkR6WbBcuNMOVaI7MaH3cZ6UAeNfj7AgEwHwMIFLPpC13YNZhno219F0lfxzTAA0N62ndWzA==", + "version": "0.11.1", + "resolved": "https://registry.npmjs.org/@firebase/functions/-/functions-0.11.1.tgz", + "integrity": "sha512-3uUa1hB79Gmy6E1gHTfzoHeZolBeHc/I/n3+lOCDe6BOos9AHmzRjKygcFE/7VA2FJjitCE0K+OHI6+OuoY8fQ==", "dependencies": { "@firebase/app-check-interop-types": "0.3.0", "@firebase/auth-interop-types": "0.2.1", - "@firebase/component": "0.6.4", + "@firebase/component": "0.6.5", "@firebase/messaging-interop-types": "0.2.0", - "@firebase/util": "1.9.3", - "node-fetch": "2.6.7", - "tslib": "^2.1.0" + "@firebase/util": "1.9.4", + "tslib": "^2.1.0", + "undici": "5.26.5" }, "peerDependencies": { "@firebase/app": "0.x" } }, "node_modules/@firebase/functions-compat": { - "version": "0.3.5", - "resolved": "https://registry.npmjs.org/@firebase/functions-compat/-/functions-compat-0.3.5.tgz", - "integrity": "sha512-uD4jwgwVqdWf6uc3NRKF8cSZ0JwGqSlyhPgackyUPe+GAtnERpS4+Vr66g0b3Gge0ezG4iyHo/EXW/Hjx7QhHw==", + "version": "0.3.7", + "resolved": "https://registry.npmjs.org/@firebase/functions-compat/-/functions-compat-0.3.7.tgz", + "integrity": "sha512-uXe6Kmku5lNogp3OpPBcOJbSvnaCOn+YxS3zlXKNU6Q/NLwcvO3RY1zwYyctCos2RemEw3KEQ7YdzcECXjHWLw==", "dependencies": { - "@firebase/component": "0.6.4", - "@firebase/functions": "0.10.0", + "@firebase/component": "0.6.5", + "@firebase/functions": "0.11.1", "@firebase/functions-types": "0.6.0", - "@firebase/util": "1.9.3", + "@firebase/util": "1.9.4", "tslib": "^2.1.0" }, "peerDependencies": { @@ -2171,13 +2180,13 @@ "integrity": "sha512-hfEw5VJtgWXIRf92ImLkgENqpL6IWpYaXVYiRkFY1jJ9+6tIhWM7IzzwbevwIIud/jaxKVdRzD7QBWfPmkwCYw==" }, "node_modules/@firebase/installations": { - "version": "0.6.4", - "resolved": "https://registry.npmjs.org/@firebase/installations/-/installations-0.6.4.tgz", - "integrity": "sha512-u5y88rtsp7NYkCHC3ElbFBrPtieUybZluXyzl7+4BsIz4sqb4vSAuwHEUgCgCeaQhvsnxDEU6icly8U9zsJigA==", + "version": "0.6.5", + "resolved": "https://registry.npmjs.org/@firebase/installations/-/installations-0.6.5.tgz", + "integrity": "sha512-0xxnQWw8rSRzu0ZOCkZaO+MJ0LkDAfwwTB2Z1SxRK6FAz5xkxD1ZUwM0WbCRni49PKubCrZYOJ6yg7tSjU7AKA==", "dependencies": { - "@firebase/component": "0.6.4", - "@firebase/util": "1.9.3", - "idb": "7.0.1", + "@firebase/component": "0.6.5", + "@firebase/util": "1.9.4", + "idb": "7.1.1", "tslib": "^2.1.0" }, "peerDependencies": { @@ -2185,14 +2194,14 @@ } }, "node_modules/@firebase/installations-compat": { - "version": "0.2.4", - "resolved": "https://registry.npmjs.org/@firebase/installations-compat/-/installations-compat-0.2.4.tgz", - "integrity": "sha512-LI9dYjp0aT9Njkn9U4JRrDqQ6KXeAmFbRC0E7jI7+hxl5YmRWysq5qgQl22hcWpTk+cm3es66d/apoDU/A9n6Q==", + "version": "0.2.5", + "resolved": "https://registry.npmjs.org/@firebase/installations-compat/-/installations-compat-0.2.5.tgz", + "integrity": "sha512-usvoIaog5CHEw082HXLrKAZ1qd4hIC3N/LDe2NqBgI3pkGE/7auLVM4Gn5gvyryp0x8z/IP1+d9fkGUj2OaGLQ==", "dependencies": { - "@firebase/component": "0.6.4", - "@firebase/installations": "0.6.4", + "@firebase/component": "0.6.5", + "@firebase/installations": "0.6.5", "@firebase/installations-types": "0.5.0", - "@firebase/util": "1.9.3", + "@firebase/util": "1.9.4", "tslib": "^2.1.0" }, "peerDependencies": { @@ -2207,11 +2216,6 @@ "@firebase/app-types": "0.x" } }, - "node_modules/@firebase/installations/node_modules/idb": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/idb/-/idb-7.0.1.tgz", - "integrity": "sha512-UUxlE7vGWK5RfB/fDwEGgRf84DY/ieqNha6msMV99UsEMQhJ1RwbCd8AYBj3QMgnE3VZnfQvm4oKVCJTYlqIgg==" - }, "node_modules/@firebase/logger": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/@firebase/logger/-/logger-0.4.0.tgz", @@ -2221,15 +2225,15 @@ } }, "node_modules/@firebase/messaging": { - "version": "0.12.4", - "resolved": "https://registry.npmjs.org/@firebase/messaging/-/messaging-0.12.4.tgz", - "integrity": "sha512-6JLZct6zUaex4g7HI3QbzeUrg9xcnmDAPTWpkoMpd/GoSVWH98zDoWXMGrcvHeCAIsLpFMe4MPoZkJbrPhaASw==", + "version": "0.12.6", + "resolved": "https://registry.npmjs.org/@firebase/messaging/-/messaging-0.12.6.tgz", + "integrity": "sha512-IORsPp9IPWq4j4yEhTOZ6GAGi3gQwGc+4yexmTAlya+qeBRSdRnJg2iIU/aj+tcKDQYr9RQuQPgHHOdFIx//vA==", "dependencies": { - "@firebase/component": "0.6.4", - "@firebase/installations": "0.6.4", + "@firebase/component": "0.6.5", + "@firebase/installations": "0.6.5", "@firebase/messaging-interop-types": "0.2.0", - "@firebase/util": "1.9.3", - "idb": "7.0.1", + "@firebase/util": "1.9.4", + "idb": "7.1.1", "tslib": "^2.1.0" }, "peerDependencies": { @@ -2237,13 +2241,13 @@ } }, "node_modules/@firebase/messaging-compat": { - "version": "0.2.4", - "resolved": "https://registry.npmjs.org/@firebase/messaging-compat/-/messaging-compat-0.2.4.tgz", - "integrity": "sha512-lyFjeUhIsPRYDPNIkYX1LcZMpoVbBWXX4rPl7c/rqc7G+EUea7IEtSt4MxTvh6fDfPuzLn7+FZADfscC+tNMfg==", + "version": "0.2.6", + "resolved": "https://registry.npmjs.org/@firebase/messaging-compat/-/messaging-compat-0.2.6.tgz", + "integrity": "sha512-Q2xC1s4L7Vpss7P7Gy6GuIS+xmJrf/vm9+gX76IK1Bo1TjoKwleCLHt1LHkPz5Rvqg5pTgzzI8qqPhBpZosFCg==", "dependencies": { - "@firebase/component": "0.6.4", - "@firebase/messaging": "0.12.4", - "@firebase/util": "1.9.3", + "@firebase/component": "0.6.5", + "@firebase/messaging": "0.12.6", + "@firebase/util": "1.9.4", "tslib": "^2.1.0" }, "peerDependencies": { @@ -2255,20 +2259,15 @@ "resolved": "https://registry.npmjs.org/@firebase/messaging-interop-types/-/messaging-interop-types-0.2.0.tgz", "integrity": "sha512-ujA8dcRuVeBixGR9CtegfpU4YmZf3Lt7QYkcj693FFannwNuZgfAYaTmbJ40dtjB81SAu6tbFPL9YLNT15KmOQ==" }, - "node_modules/@firebase/messaging/node_modules/idb": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/idb/-/idb-7.0.1.tgz", - "integrity": "sha512-UUxlE7vGWK5RfB/fDwEGgRf84DY/ieqNha6msMV99UsEMQhJ1RwbCd8AYBj3QMgnE3VZnfQvm4oKVCJTYlqIgg==" - }, "node_modules/@firebase/performance": { - "version": "0.6.4", - "resolved": "https://registry.npmjs.org/@firebase/performance/-/performance-0.6.4.tgz", - "integrity": "sha512-HfTn/bd8mfy/61vEqaBelNiNnvAbUtME2S25A67Nb34zVuCSCRIX4SseXY6zBnOFj3oLisaEqhVcJmVPAej67g==", + "version": "0.6.5", + "resolved": "https://registry.npmjs.org/@firebase/performance/-/performance-0.6.5.tgz", + "integrity": "sha512-OzAGcWhOqEFH9GdwUuY0oC5FSlnMejcnmSAhR+EjpI7exdDvixyLyCR4txjSHYNTbumrFBG+EP8GO11CNXRaJA==", "dependencies": { - "@firebase/component": "0.6.4", - "@firebase/installations": "0.6.4", + "@firebase/component": "0.6.5", + "@firebase/installations": "0.6.5", "@firebase/logger": "0.4.0", - "@firebase/util": "1.9.3", + "@firebase/util": "1.9.4", "tslib": "^2.1.0" }, "peerDependencies": { @@ -2276,15 +2275,15 @@ } }, "node_modules/@firebase/performance-compat": { - "version": "0.2.4", - "resolved": "https://registry.npmjs.org/@firebase/performance-compat/-/performance-compat-0.2.4.tgz", - "integrity": "sha512-nnHUb8uP9G8islzcld/k6Bg5RhX62VpbAb/Anj7IXs/hp32Eb2LqFPZK4sy3pKkBUO5wcrlRWQa6wKOxqlUqsg==", + "version": "0.2.5", + "resolved": "https://registry.npmjs.org/@firebase/performance-compat/-/performance-compat-0.2.5.tgz", + "integrity": "sha512-jJwJkVyDcIMBaVGrZ6CRGs4m5FCZsWB5QCWYI3FdsHyIa9/TfteNDilxj9wGciF2naFIHDW7TgE69U5dAH9Ktg==", "dependencies": { - "@firebase/component": "0.6.4", + "@firebase/component": "0.6.5", "@firebase/logger": "0.4.0", - "@firebase/performance": "0.6.4", + "@firebase/performance": "0.6.5", "@firebase/performance-types": "0.2.0", - "@firebase/util": "1.9.3", + "@firebase/util": "1.9.4", "tslib": "^2.1.0" }, "peerDependencies": { @@ -2297,14 +2296,14 @@ "integrity": "sha512-kYrbr8e/CYr1KLrLYZZt2noNnf+pRwDq2KK9Au9jHrBMnb0/C9X9yWSXmZkFt4UIdsQknBq8uBB7fsybZdOBTA==" }, "node_modules/@firebase/remote-config": { - "version": "0.4.4", - "resolved": "https://registry.npmjs.org/@firebase/remote-config/-/remote-config-0.4.4.tgz", - "integrity": "sha512-x1ioTHGX8ZwDSTOVp8PBLv2/wfwKzb4pxi0gFezS5GCJwbLlloUH4YYZHHS83IPxnua8b6l0IXUaWd0RgbWwzQ==", + "version": "0.4.5", + "resolved": "https://registry.npmjs.org/@firebase/remote-config/-/remote-config-0.4.5.tgz", + "integrity": "sha512-rGLqc/4OmxrS39RA9kgwa6JmgWytQuMo+B8pFhmGp3d++x2Hf9j+MLQfhOLyyUo64fNw20J19mLXhrXvKHsjZQ==", "dependencies": { - "@firebase/component": "0.6.4", - "@firebase/installations": "0.6.4", + "@firebase/component": "0.6.5", + "@firebase/installations": "0.6.5", "@firebase/logger": "0.4.0", - "@firebase/util": "1.9.3", + "@firebase/util": "1.9.4", "tslib": "^2.1.0" }, "peerDependencies": { @@ -2312,15 +2311,15 @@ } }, "node_modules/@firebase/remote-config-compat": { - "version": "0.2.4", - "resolved": "https://registry.npmjs.org/@firebase/remote-config-compat/-/remote-config-compat-0.2.4.tgz", - "integrity": "sha512-FKiki53jZirrDFkBHglB3C07j5wBpitAaj8kLME6g8Mx+aq7u9P7qfmuSRytiOItADhWUj7O1JIv7n9q87SuwA==", + "version": "0.2.5", + "resolved": "https://registry.npmjs.org/@firebase/remote-config-compat/-/remote-config-compat-0.2.5.tgz", + "integrity": "sha512-ImkNnLuGrD/bylBHDJigSY6LMwRrwt37wQbsGZhWG4QQ6KLzHzSf0nnFRRFvkOZodEUE57Ib8l74d6Yn/6TDUQ==", "dependencies": { - "@firebase/component": "0.6.4", + "@firebase/component": "0.6.5", "@firebase/logger": "0.4.0", - "@firebase/remote-config": "0.4.4", + "@firebase/remote-config": "0.4.5", "@firebase/remote-config-types": "0.3.0", - "@firebase/util": "1.9.3", + "@firebase/util": "1.9.4", "tslib": "^2.1.0" }, "peerDependencies": { @@ -2333,28 +2332,28 @@ "integrity": "sha512-RtEH4vdcbXZuZWRZbIRmQVBNsE7VDQpet2qFvq6vwKLBIQRQR5Kh58M4ok3A3US8Sr3rubYnaGqZSurCwI8uMA==" }, "node_modules/@firebase/storage": { - "version": "0.11.2", - "resolved": "https://registry.npmjs.org/@firebase/storage/-/storage-0.11.2.tgz", - "integrity": "sha512-CtvoFaBI4hGXlXbaCHf8humajkbXhs39Nbh6MbNxtwJiCqxPy9iH3D3CCfXAvP0QvAAwmJUTK3+z9a++Kc4nkA==", + "version": "0.12.1", + "resolved": "https://registry.npmjs.org/@firebase/storage/-/storage-0.12.1.tgz", + "integrity": "sha512-KJ5NV7FUh54TeTlEjdkTTX60ciCKOp9EqlbLnpdcXUYRJg0Z4810TXbilPc1z7fTIG4iPjtdi95bGE9n4dBX8A==", "dependencies": { - "@firebase/component": "0.6.4", - "@firebase/util": "1.9.3", - "node-fetch": "2.6.7", - "tslib": "^2.1.0" + "@firebase/component": "0.6.5", + "@firebase/util": "1.9.4", + "tslib": "^2.1.0", + "undici": "5.26.5" }, "peerDependencies": { "@firebase/app": "0.x" } }, "node_modules/@firebase/storage-compat": { - "version": "0.3.2", - "resolved": "https://registry.npmjs.org/@firebase/storage-compat/-/storage-compat-0.3.2.tgz", - "integrity": "sha512-wvsXlLa9DVOMQJckbDNhXKKxRNNewyUhhbXev3t8kSgoCotd1v3MmqhKKz93ePhDnhHnDs7bYHy+Qa8dRY6BXw==", + "version": "0.3.4", + "resolved": "https://registry.npmjs.org/@firebase/storage-compat/-/storage-compat-0.3.4.tgz", + "integrity": "sha512-Y0m5e2gS/wB9Ioth2X/Sgz76vcxvqgQrCmfa9qwhss/N31kxY2Gks6Frv0nrE18AjVfcSmcfDitqUwxcMOTRSg==", "dependencies": { - "@firebase/component": "0.6.4", - "@firebase/storage": "0.11.2", + "@firebase/component": "0.6.5", + "@firebase/storage": "0.12.1", "@firebase/storage-types": "0.8.0", - "@firebase/util": "1.9.3", + "@firebase/util": "1.9.4", "tslib": "^2.1.0" }, "peerDependencies": { @@ -2371,24 +2370,24 @@ } }, "node_modules/@firebase/util": { - "version": "1.9.3", - "resolved": "https://registry.npmjs.org/@firebase/util/-/util-1.9.3.tgz", - "integrity": "sha512-DY02CRhOZwpzO36fHpuVysz6JZrscPiBXD0fXp6qSrL9oNOx5KWICKdR95C0lSITzxp0TZosVyHqzatE8JbcjA==", + "version": "1.9.4", + "resolved": "https://registry.npmjs.org/@firebase/util/-/util-1.9.4.tgz", + "integrity": "sha512-WLonYmS1FGHT97TsUmRN3qnTh5TeeoJp1Gg5fithzuAgdZOUtsYECfy7/noQ3llaguios8r5BuXSEiK82+UrxQ==", "dependencies": { "tslib": "^2.1.0" } }, "node_modules/@firebase/webchannel-wrapper": { - "version": "0.10.2", - "resolved": "https://registry.npmjs.org/@firebase/webchannel-wrapper/-/webchannel-wrapper-0.10.2.tgz", - "integrity": "sha512-xDxhD9++451HuCv3xKBEdSYaArX9NcokODXZYH/MxGw1XFFOz7OKkTRItZ5wf6npBN/inwp8dUZCP7SpAg46yQ==" + "version": "0.10.5", + "resolved": "https://registry.npmjs.org/@firebase/webchannel-wrapper/-/webchannel-wrapper-0.10.5.tgz", + "integrity": "sha512-eSkJsnhBWv5kCTSU1tSUVl9mpFu+5NXXunZc83le8GMjMlsWwQArSc7cJJ4yl+aDFY0NGLi0AjZWMn1axOrkRg==" }, "node_modules/@grpc/grpc-js": { - "version": "1.8.21", - "resolved": "https://registry.npmjs.org/@grpc/grpc-js/-/grpc-js-1.8.21.tgz", - "integrity": "sha512-KeyQeZpxeEBSqFVTi3q2K7PiPXmgBfECc4updA1ejCLjYmoAlvvM3ZMp5ztTDUCUQmoY3CpDxvchjO1+rFkoHg==", + "version": "1.9.14", + "resolved": "https://registry.npmjs.org/@grpc/grpc-js/-/grpc-js-1.9.14.tgz", + "integrity": "sha512-nOpuzZ2G3IuMFN+UPPpKrC6NsLmWsTqSsm66IRfnBt1D4pwTqE27lmbpcPM+l2Ua4gE7PfjRHI6uedAy7hoXUw==", "dependencies": { - "@grpc/proto-loader": "^0.7.0", + "@grpc/proto-loader": "^0.7.8", "@types/node": ">=12.12.47" }, "engines": { @@ -2396,9 +2395,9 @@ } }, "node_modules/@grpc/proto-loader": { - "version": "0.7.9", - "resolved": "https://registry.npmjs.org/@grpc/proto-loader/-/proto-loader-0.7.9.tgz", - "integrity": "sha512-YJsOehVXzgurc+lLAxYnlSMc1p/Gu6VAvnfx0ATi2nzvr0YZcjhmZDeY8SeAKv1M7zE3aEJH0Xo9mK1iZ8GYoQ==", + "version": "0.7.10", + "resolved": "https://registry.npmjs.org/@grpc/proto-loader/-/proto-loader-0.7.10.tgz", + "integrity": "sha512-CAqDfoaQ8ykFd9zqBDn4k6iWT9loLAlc2ETmDFS9JCD70gDcnA4L3AFEo2iV7KyAtAAHFW9ftq1Fz+Vsgq80RQ==", "dependencies": { "lodash.camelcase": "^4.3.0", "long": "^5.0.0", @@ -10028,36 +10027,36 @@ } }, "node_modules/firebase": { - "version": "10.3.0", - "resolved": "https://registry.npmjs.org/firebase/-/firebase-10.3.0.tgz", - "integrity": "sha512-1dy6KqAvGlnFUEFE+IaHQNygG/4v1OwB5KVIC/G1/qwbHEFws0FVHe3n/aRZ+Oo0tINO9s2Lim496p9wprMbNQ==", + "version": "10.8.0", + "resolved": "https://registry.npmjs.org/firebase/-/firebase-10.8.0.tgz", + "integrity": "sha512-UJpC24vw8JFuHEOQyArBGKTUd7+kohLISCzHyn0M/prP0KOTx2io1eyLliEid330QqnWI7FOlPxoU97qecCSfQ==", "dependencies": { - "@firebase/analytics": "0.10.0", - "@firebase/analytics-compat": "0.2.6", - "@firebase/app": "0.9.17", - "@firebase/app-check": "0.8.0", - "@firebase/app-check-compat": "0.3.7", - "@firebase/app-compat": "0.2.17", + "@firebase/analytics": "0.10.1", + "@firebase/analytics-compat": "0.2.7", + "@firebase/app": "0.9.27", + "@firebase/app-check": "0.8.2", + "@firebase/app-check-compat": "0.3.9", + "@firebase/app-compat": "0.2.27", "@firebase/app-types": "0.9.0", - "@firebase/auth": "1.3.0", - "@firebase/auth-compat": "0.4.6", - "@firebase/database": "1.0.1", - "@firebase/database-compat": "1.0.1", - "@firebase/firestore": "4.1.2", - "@firebase/firestore-compat": "0.3.16", - "@firebase/functions": "0.10.0", - "@firebase/functions-compat": "0.3.5", - "@firebase/installations": "0.6.4", - "@firebase/installations-compat": "0.2.4", - "@firebase/messaging": "0.12.4", - "@firebase/messaging-compat": "0.2.4", - "@firebase/performance": "0.6.4", - "@firebase/performance-compat": "0.2.4", - "@firebase/remote-config": "0.4.4", - "@firebase/remote-config-compat": "0.2.4", - "@firebase/storage": "0.11.2", - "@firebase/storage-compat": "0.3.2", - "@firebase/util": "1.9.3" + "@firebase/auth": "1.6.0", + "@firebase/auth-compat": "0.5.2", + "@firebase/database": "1.0.3", + "@firebase/database-compat": "1.0.3", + "@firebase/firestore": "4.4.2", + "@firebase/firestore-compat": "0.3.25", + "@firebase/functions": "0.11.1", + "@firebase/functions-compat": "0.3.7", + "@firebase/installations": "0.6.5", + "@firebase/installations-compat": "0.2.5", + "@firebase/messaging": "0.12.6", + "@firebase/messaging-compat": "0.2.6", + "@firebase/performance": "0.6.5", + "@firebase/performance-compat": "0.2.5", + "@firebase/remote-config": "0.4.5", + "@firebase/remote-config-compat": "0.2.5", + "@firebase/storage": "0.12.1", + "@firebase/storage-compat": "0.3.4", + "@firebase/util": "1.9.4" } }, "node_modules/flagged-respawn": { @@ -16274,25 +16273,6 @@ "tslib": "^2.0.3" } }, - "node_modules/node-fetch": { - "version": "2.6.7", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", - "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", - "dependencies": { - "whatwg-url": "^5.0.0" - }, - "engines": { - "node": "4.x || >=6.0.0" - }, - "peerDependencies": { - "encoding": "^0.1.0" - }, - "peerDependenciesMeta": { - "encoding": { - "optional": true - } - } - }, "node_modules/node-forge": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.3.1.tgz", @@ -18007,9 +17987,9 @@ } }, "node_modules/protobufjs": { - "version": "7.2.5", - "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-7.2.5.tgz", - "integrity": "sha512-gGXRSXvxQ7UiPgfw8gevrfRWcTlSbOFg+p/N+JVJEK5VhueL2miT6qTymqAmjr1Q5WbOCyJbyrk6JfWKwlFn6A==", + "version": "7.2.6", + "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-7.2.6.tgz", + "integrity": "sha512-dgJaEDDL6x8ASUZ1YqWciTRrdOuYNzoOf27oHNfdyvKqHr5i0FV7FSLU+aIeFjyFgVxrpTOtQUi0BLLBymZaBw==", "hasInstallScript": true, "dependencies": { "@protobufjs/aspromise": "^1.1.2", @@ -20905,11 +20885,6 @@ "node": ">= 4.0.0" } }, - "node_modules/tr46": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", - "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" - }, "node_modules/tree-kill": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/tree-kill/-/tree-kill-1.2.2.tgz", @@ -21423,6 +21398,17 @@ "integrity": "sha1-5qdUzI8V5YmHqpy9J69m/W9OWvk=", "dev": true }, + "node_modules/undici": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici/-/undici-5.26.5.tgz", + "integrity": "sha512-cSb4bPFd5qgR7qr2jYAi0hlX9n5YKK2ONKkLFkxl+v/9BvC0sOpZjBHDBSXc5lWAf5ty9oZdRXytBIHzgUcerw==", + "dependencies": { + "@fastify/busboy": "^2.0.0" + }, + "engines": { + "node": ">=14.0" + } + }, "node_modules/unicode-canonical-property-names-ecmascript": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-2.0.0.tgz", @@ -21923,11 +21909,6 @@ "defaults": "^1.0.3" } }, - "node_modules/webidl-conversions": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", - "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" - }, "node_modules/webpack": { "version": "5.72.0", "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.72.0.tgz", @@ -22467,15 +22448,6 @@ "node": ">=12" } }, - "node_modules/whatwg-url": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", - "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", - "dependencies": { - "tr46": "~0.0.3", - "webidl-conversions": "^3.0.0" - } - }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", diff --git a/frontend/package.json b/frontend/package.json index d286dc486..4d22e8d10 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -89,7 +89,7 @@ "crypto-browserify": "3.12.0", "damerau-levenshtein": "1.0.8", "date-fns": "2.28.0", - "firebase": "10.3.0", + "firebase": "10.8.0", "hangul-js": "0.2.6", "howler": "2.2.3", "html2canvas": "1.4.1", diff --git a/frontend/src/ts/ape/adapters/axios-adapter.ts b/frontend/src/ts/ape/adapters/axios-adapter.ts index 560bee269..8e1cddad0 100644 --- a/frontend/src/ts/ape/adapters/axios-adapter.ts +++ b/frontend/src/ts/ape/adapters/axios-adapter.ts @@ -1,4 +1,4 @@ -import { Auth } from "../../firebase"; +import { getAuthenticatedUser, isAuthenticated } from "../../firebase"; import { getIdToken } from "firebase/auth"; import axios, { AxiosRequestConfig, AxiosResponse } from "axios"; import { CLIENT_VERSION } from "../../version"; @@ -17,8 +17,9 @@ type AxiosClientDataMethod = ( async function adaptRequestOptions( options: Ape.RequestOptions ): Promise { - const currentUser = Auth?.currentUser; - const idToken = (currentUser && (await getIdToken(currentUser))) ?? ""; + const idToken = isAuthenticated() + ? await getIdToken(getAuthenticatedUser()) + : ""; return { params: options.searchQuery, diff --git a/frontend/src/ts/commandline/index.ts b/frontend/src/ts/commandline/index.ts index 77ed43b7f..c132085da 100644 --- a/frontend/src/ts/commandline/index.ts +++ b/frontend/src/ts/commandline/index.ts @@ -9,7 +9,7 @@ import * as AnalyticsController from "../controllers/analytics-controller"; import * as PageTransition from "../states/page-transition"; import * as TestWords from "../test/test-words"; import * as ActivePage from "../states/active-page"; -import { Auth } from "../firebase"; +import { isAuthenticated } from "../firebase"; import { isAnyPopupVisible, isElementVisible, @@ -804,7 +804,7 @@ $(".pageTest").on("click", "#testModesNotice .textButton", (event) => { $("footer").on("click", ".leftright .right .current-theme", (e) => { if (e.shiftKey) { if (!Config.customTheme) { - if (Auth?.currentUser) { + if (isAuthenticated()) { if ((DB.getSnapshot()?.customThemes.length ?? 0) < 1) { Notifications.add("No custom themes!", 0); UpdateConfig.setCustomTheme(false); diff --git a/frontend/src/ts/commandline/lists/custom-themes-list.ts b/frontend/src/ts/commandline/lists/custom-themes-list.ts index cf3bb6f79..336855544 100644 --- a/frontend/src/ts/commandline/lists/custom-themes-list.ts +++ b/frontend/src/ts/commandline/lists/custom-themes-list.ts @@ -1,5 +1,5 @@ import * as UpdateConfig from "../../config"; -import { Auth } from "../../firebase"; +import { isAuthenticated } from "../../firebase"; import * as DB from "../../db"; import * as ThemeController from "../../controllers/theme-controller"; @@ -17,13 +17,13 @@ const commands: MonkeyTypes.Command[] = [ icon: "fa-palette", subgroup, available: (): boolean => { - return !!Auth?.currentUser; + return isAuthenticated(); }, }, ]; export function update(): void { - if (!Auth?.currentUser) { + if (!isAuthenticated()) { return; } diff --git a/frontend/src/ts/commandline/lists/presets.ts b/frontend/src/ts/commandline/lists/presets.ts index 23166f0d8..acfcea52a 100644 --- a/frontend/src/ts/commandline/lists/presets.ts +++ b/frontend/src/ts/commandline/lists/presets.ts @@ -3,7 +3,7 @@ import * as ModesNotice from "../../elements/modes-notice"; import * as Settings from "../../pages/settings"; import * as PresetController from "../../controllers/preset-controller"; import * as EditPresetPopup from "../../popups/edit-preset-popup"; -import { Auth } from "../../firebase"; +import { isAuthenticated } from "../../firebase"; const subgroup: MonkeyTypes.CommandsSubgroup = { title: "Presets...", @@ -21,7 +21,7 @@ const commands: MonkeyTypes.Command[] = [ icon: "fa-sliders-h", subgroup, available: (): boolean => { - return !!Auth?.currentUser; + return isAuthenticated(); }, }, ]; diff --git a/frontend/src/ts/commandline/lists/quote-length.ts b/frontend/src/ts/commandline/lists/quote-length.ts index f05214da4..7b1f5fdde 100644 --- a/frontend/src/ts/commandline/lists/quote-length.ts +++ b/frontend/src/ts/commandline/lists/quote-length.ts @@ -1,6 +1,6 @@ import * as UpdateConfig from "../../config"; import * as TestLogic from "../../test/test-logic"; -import { Auth } from "../../firebase"; +import { isAuthenticated } from "../../firebase"; const commands: MonkeyTypes.Command[] = [ { @@ -72,7 +72,7 @@ const commands: MonkeyTypes.Command[] = [ configValue: -3, configValueMode: "include", available: (): boolean => { - return !!Auth?.currentUser; + return isAuthenticated(); }, exec: (): void => { UpdateConfig.setMode("quote"); diff --git a/frontend/src/ts/commandline/lists/random-theme.ts b/frontend/src/ts/commandline/lists/random-theme.ts index 775579a1f..c2b29cae7 100644 --- a/frontend/src/ts/commandline/lists/random-theme.ts +++ b/frontend/src/ts/commandline/lists/random-theme.ts @@ -1,5 +1,5 @@ import * as UpdateConfig from "../../config"; -import { Auth } from "../../firebase"; +import { isAuthenticated } from "../../firebase"; import * as Notifications from "../../elements/notifications"; const subgroup: MonkeyTypes.CommandsSubgroup = { @@ -51,7 +51,7 @@ const subgroup: MonkeyTypes.CommandsSubgroup = { display: "custom", configValue: "custom", exec: (): void => { - if (!Auth?.currentUser) { + if (!isAuthenticated()) { Notifications.add( "Multiple custom themes are available to logged in users only", 0 diff --git a/frontend/src/ts/commandline/lists/tags.ts b/frontend/src/ts/commandline/lists/tags.ts index c36d5e848..932289662 100644 --- a/frontend/src/ts/commandline/lists/tags.ts +++ b/frontend/src/ts/commandline/lists/tags.ts @@ -4,7 +4,7 @@ import * as ModesNotice from "../../elements/modes-notice"; import * as TagController from "../../controllers/tag-controller"; import Config from "../../config"; import * as PaceCaret from "../../test/pace-caret"; -import { Auth } from "../../firebase"; +import { isAuthenticated } from "../../firebase"; const subgroup: MonkeyTypes.CommandsSubgroup = { title: "Change tags...", @@ -22,7 +22,7 @@ const commands: MonkeyTypes.Command[] = [ icon: "fa-tag", subgroup, available: (): boolean => { - return !!Auth?.currentUser; + return isAuthenticated(); }, }, ]; diff --git a/frontend/src/ts/config.ts b/frontend/src/ts/config.ts index 23dac87db..9f93316c9 100644 --- a/frontend/src/ts/config.ts +++ b/frontend/src/ts/config.ts @@ -7,7 +7,7 @@ import { } from "./config-validation"; import * as ConfigEvent from "./observables/config-event"; import DefaultConfig from "./constants/default-config"; -import { Auth } from "./firebase"; +import { isAuthenticated } from "./firebase"; import * as AnalyticsController from "./controllers/analytics-controller"; import * as AccountButton from "./elements/account-button"; import { debounce } from "throttle-debounce"; @@ -466,7 +466,7 @@ export function setPaceCaret( } if (document.readyState === "complete") { - if (val === "pb" && !Auth?.currentUser) { + if (val === "pb" && !isAuthenticated()) { Notifications.add("PB pace caret is unavailable without an account", 0); return false; } @@ -1435,7 +1435,7 @@ export function setRandomTheme( } if (val === "custom") { - if (!Auth?.currentUser) { + if (!isAuthenticated()) { config.randomTheme = val; return false; } diff --git a/frontend/src/ts/controllers/account-controller.ts b/frontend/src/ts/controllers/account-controller.ts index 76e007187..6af719cbc 100644 --- a/frontend/src/ts/controllers/account-controller.ts +++ b/frontend/src/ts/controllers/account-controller.ts @@ -32,7 +32,7 @@ import { User as UserType, Unsubscribe, } from "firebase/auth"; -import { Auth } from "../firebase"; +import { Auth, getAuthenticatedUser, isAuthenticated } from "../firebase"; import { dispatch as dispatchSignUpEvent } from "../observables/google-sign-up-event"; import { hideFavoriteQuoteLength, @@ -412,8 +412,8 @@ async function addGoogleAuth(): Promise { return; } Loader.show(); - if (Auth.currentUser === null) return; - linkWithPopup(Auth.currentUser, gmailProvider) + if (!isAuthenticated()) return; + linkWithPopup(getAuthenticatedUser(), gmailProvider) .then(function () { Loader.hide(); Notifications.add("Google authentication added", 1); @@ -435,7 +435,7 @@ export function signOut(): void { }); return; } - if (!Auth.currentUser) return; + if (!isAuthenticated()) return; Auth.signOut() .then(function () { Notifications.add("Signed out", 0, { @@ -629,7 +629,7 @@ $("header .signInOut").on("click", () => { }); return; } - if (Auth.currentUser) { + if (isAuthenticated()) { signOut(); signedOutThisSession = true; } else { diff --git a/frontend/src/ts/controllers/route-controller.ts b/frontend/src/ts/controllers/route-controller.ts index df767cdf6..f87ff87f4 100644 --- a/frontend/src/ts/controllers/route-controller.ts +++ b/frontend/src/ts/controllers/route-controller.ts @@ -2,7 +2,7 @@ import * as PageController from "./page-controller"; import * as Leaderboards from "../elements/leaderboards"; import * as TestUI from "../test/test-ui"; import * as PageTransition from "../states/page-transition"; -import { Auth } from "../firebase"; +import { Auth, isAuthenticated } from "../firebase"; //source: https://www.youtube.com/watch?v=OstALBk-jTc // https://www.youtube.com/watch?v=OstALBk-jTc @@ -87,7 +87,7 @@ const routes: Route[] = [ navigate("/"); return; } - if (Auth.currentUser) { + if (isAuthenticated()) { navigate("/account"); return; } diff --git a/frontend/src/ts/db.ts b/frontend/src/ts/db.ts index 5c53dd9c6..0d8e57398 100644 --- a/frontend/src/ts/db.ts +++ b/frontend/src/ts/db.ts @@ -2,7 +2,7 @@ import Ape from "./ape"; import * as Notifications from "./elements/notifications"; import * as LoadingPage from "./pages/loading"; import DefaultConfig from "./constants/default-config"; -import { Auth } from "./firebase"; +import { isAuthenticated } from "./firebase"; import { defaultSnap } from "./constants/default-snapshot"; import * as ConnectionState from "./states/connection"; import { getFunboxList, lastElementFromArray } from "./utils/misc"; @@ -45,7 +45,7 @@ export async function initSnapshot(): Promise< //send api request with token that returns tags, presets, and data needed for snap const snap = { ...defaultSnap }; try { - if (!Auth?.currentUser) return false; + if (!isAuthenticated()) return false; // if (ActivePage.get() === "loading") { // LoadingPage.updateBar(22.5); // } else { @@ -228,8 +228,8 @@ export async function initSnapshot(): Promise< } export async function getUserResults(offset?: number): Promise { - const user = Auth?.currentUser; - if (!user) return false; + if (!isAuthenticated()) return false; + if (!dbSnapshot) return false; if ( dbSnapshot.results !== undefined && @@ -336,8 +336,7 @@ export async function editCustomTheme( themeId: string, newTheme: MonkeyTypes.RawCustomTheme ): Promise { - const user = Auth?.currentUser; - if (!user) return false; + if (!isAuthenticated()) return false; if (!dbSnapshot) return false; const customTheme = dbSnapshot.customThemes.find((t) => t._id === themeId); @@ -367,8 +366,7 @@ export async function editCustomTheme( } export async function deleteCustomTheme(themeId: string): Promise { - const user = Auth?.currentUser; - if (!user) return false; + if (!isAuthenticated()) return false; if (!dbSnapshot) return false; const customTheme = dbSnapshot.customThemes.find((t) => t._id === themeId); @@ -891,7 +889,7 @@ export async function updateLbMemory( } export async function saveConfig(config: SharedTypes.Config): Promise { - if (Auth?.currentUser) { + if (isAuthenticated()) { const response = await Ape.configs.save(config); if (response.status !== 200) { Notifications.add("Failed to save config: " + response.message, -1); diff --git a/frontend/src/ts/elements/account-button.ts b/frontend/src/ts/elements/account-button.ts index cf4a579b0..2364e1222 100644 --- a/frontend/src/ts/elements/account-button.ts +++ b/frontend/src/ts/elements/account-button.ts @@ -1,5 +1,5 @@ import { getSnapshot } from "../db"; -import { Auth } from "../firebase"; +import { isAuthenticated } from "../firebase"; import * as Misc from "../utils/misc"; import { getAll } from "./theme-colors"; import * as SlowTimer from "../states/slow-timer"; @@ -100,7 +100,7 @@ export async function update( discordId?: string, discordAvatar?: string ): Promise { - if (Auth?.currentUser) { + if (isAuthenticated()) { if (xp !== undefined) { $("header nav .level").text(Math.floor(Misc.getLevel(xp))); $("header nav .bar").css({ diff --git a/frontend/src/ts/elements/alerts.ts b/frontend/src/ts/elements/alerts.ts index 070a758c3..d64a211cd 100644 --- a/frontend/src/ts/elements/alerts.ts +++ b/frontend/src/ts/elements/alerts.ts @@ -1,6 +1,6 @@ import formatDistanceToNowStrict from "date-fns/formatDistanceToNowStrict"; import Ape from "../ape"; -import { Auth } from "../firebase"; +import { isAuthenticated } from "../firebase"; import * as AccountButton from "../elements/account-button"; import * as DB from "../db"; import * as NotificationEvent from "../observables/notification-event"; @@ -133,7 +133,7 @@ async function show(): Promise { "easeOutCubic" ); - if (Auth?.currentUser) { + if (isAuthenticated()) { $("#alertsPopup .accountAlerts").removeClass("hidden"); $("#alertsPopup .separator.accountSeparator").removeClass("hidden"); $("#alertsPopup .accountAlerts .list").html(` @@ -160,7 +160,7 @@ async function show(): Promise { }, 100, () => { - if (Auth?.currentUser) { + if (isAuthenticated()) { void getAccountAlerts(); } } diff --git a/frontend/src/ts/elements/leaderboards.ts b/frontend/src/ts/elements/leaderboards.ts index 2a63c010b..5fe917aa1 100644 --- a/frontend/src/ts/elements/leaderboards.ts +++ b/frontend/src/ts/elements/leaderboards.ts @@ -5,7 +5,7 @@ import * as Misc from "../utils/misc"; import { get as getTypingSpeedUnit } from "../utils/typing-speed-units"; import * as Notifications from "./notifications"; import format from "date-fns/format"; -import { Auth } from "../firebase"; +import { isAuthenticated } from "../firebase"; import differenceInSeconds from "date-fns/differenceInSeconds"; import { getHTMLById as getBadgeHTMLbyId } from "../controllers/badge-controller"; import * as ConnectionState from "../states/connection"; @@ -143,7 +143,7 @@ function updateFooter(lb: LbKey): void { side = "right"; } - if (Auth?.currentUser === undefined) { + if (!isAuthenticated()) { $(`#leaderboardsWrapper table.${side} tfoot`).html(` @@ -442,7 +442,7 @@ async function update(): Promise { const lbRankRequests: Promise< Ape.HttpClientResponse >[] = []; - if (Auth?.currentUser !== undefined) { + if (isAuthenticated()) { lbRankRequests.push( ...timeModes.map(async (mode2) => { return Ape.leaderboards.getRank({ @@ -643,7 +643,7 @@ export function show(): void { } Skeleton.append(wrapperId); if (!Misc.isPopupVisible("leaderboardsWrapper")) { - if (Auth?.currentUser !== undefined) { + if (isAuthenticated()) { $("#leaderboardsWrapper #leaderboards .rightTableJumpToMe").removeClass( "disabled" ); diff --git a/frontend/src/ts/elements/modes-notice.ts b/frontend/src/ts/elements/modes-notice.ts index 67c24d5d1..d813172e6 100644 --- a/frontend/src/ts/elements/modes-notice.ts +++ b/frontend/src/ts/elements/modes-notice.ts @@ -5,7 +5,7 @@ import * as Last10Average from "../elements/last-10-average"; import Config from "../config"; import * as TestWords from "../test/test-words"; import * as ConfigEvent from "../observables/config-event"; -import { Auth } from "../firebase"; +import { isAuthenticated } from "../firebase"; import * as CustomTextState from "../states/custom-text-name"; import { get as getTypingSpeedUnit } from "../utils/typing-speed-units"; import { getLanguageDisplayString, roundTo2 } from "../utils/misc"; @@ -155,7 +155,7 @@ export async function update(): Promise { avgAcc = Math.round(avgAcc); } - if (Auth?.currentUser && avgWPM > 0) { + if (isAuthenticated() && avgWPM > 0) { const avgWPMText = ["speed", "both"].includes(Config.showAverage) ? getTypingSpeedUnit(Config.typingSpeedUnit).convertWithUnitSuffix( avgWPM, diff --git a/frontend/src/ts/firebase.ts b/frontend/src/ts/firebase.ts index 521771c16..359b35277 100644 --- a/frontend/src/ts/firebase.ts +++ b/frontend/src/ts/firebase.ts @@ -1,6 +1,6 @@ // Import the functions you need from the SDKs you need import { FirebaseApp, initializeApp } from "firebase/app"; -import { getAuth, Auth as AuthType } from "firebase/auth"; +import { getAuth, Auth as AuthType, User } from "firebase/auth"; import { firebaseConfig } from "./constants/firebase-config"; // eslint-disable-line require-path-exists/exists import * as Notifications from "./elements/notifications"; import { createErrorMessage, isDevEnvironment } from "./utils/misc"; @@ -9,6 +9,19 @@ import { createErrorMessage, isDevEnvironment } from "./utils/misc"; export let app: FirebaseApp | undefined; export let Auth: AuthType | undefined; +export function isAuthenticated(): boolean { + return Auth?.currentUser !== undefined && Auth?.currentUser !== null; +} + +export function getAuthenticatedUser(): User { + const user = Auth?.currentUser; + if (user === undefined || user === null) + throw new Error( + "User authentication is required but no user is logged in." + ); + return user; +} + try { app = initializeApp(firebaseConfig); Auth = getAuth(app); diff --git a/frontend/src/ts/pages/settings.ts b/frontend/src/ts/pages/settings.ts index 0c0dca105..9677f4de8 100644 --- a/frontend/src/ts/pages/settings.ts +++ b/frontend/src/ts/pages/settings.ts @@ -14,7 +14,7 @@ import * as ActivePage from "../states/active-page"; import * as ApeKeysPopup from "../popups/ape-keys-popup"; import * as CookiePopup from "../popups/cookie-popup"; import Page from "./page"; -import { Auth } from "../firebase"; +import { getAuthenticatedUser, isAuthenticated } from "../firebase"; import Ape from "../ape"; import { areFunboxesCompatible } from "../test/funbox/funbox-validation"; import { get as getTypingSpeedUnit } from "../utils/typing-speed-units"; @@ -716,7 +716,7 @@ function showAccountSection(): void { export function updateDiscordSection(): void { //no code and no discord - if (!Auth?.currentUser) { + if (!isAuthenticated()) { $(".pageSettings .section.discordIntegration").addClass("hidden"); } else { if (!DB.getSnapshot()) return; @@ -743,8 +743,8 @@ export function updateAuthSections(): void { $(".pageSettings .section.passwordAuthSettings button").addClass("hidden"); $(".pageSettings .section.googleAuthSettings button").addClass("hidden"); - const user = Auth?.currentUser; - if (!user) return; + if (!isAuthenticated()) return; + const user = getAuthenticatedUser(); const passwordProvider = user.providerData.find( (provider) => provider.providerId === "password" @@ -817,7 +817,7 @@ function setActiveFunboxButton(): void { } function refreshTagsSettingsSection(): void { - if (Auth?.currentUser && DB.getSnapshot()) { + if (isAuthenticated() && DB.getSnapshot()) { const tagsEl = $(".pageSettings .section.tags .tagsList").empty(); DB.getSnapshot()?.tags?.forEach((tag) => { // let tagPbString = "No PB found"; @@ -854,7 +854,7 @@ function refreshTagsSettingsSection(): void { } function refreshPresetsSettingsSection(): void { - if (Auth?.currentUser && DB.getSnapshot()) { + if (isAuthenticated() && DB.getSnapshot()) { const presetsEl = $(".pageSettings .section.presets .presetsList").empty(); DB.getSnapshot()?.presets?.forEach((preset: MonkeyTypes.SnapshotPreset) => { presetsEl.append(` @@ -939,7 +939,7 @@ export async function update(groupUpdate = true): Promise { ).addClass("hidden"); } - if (Auth?.currentUser) { + if (isAuthenticated()) { showAccountSection(); } else { hideAccountSection(); diff --git a/frontend/src/ts/popups/quote-search-popup.ts b/frontend/src/ts/popups/quote-search-popup.ts index e701a7164..6117ccd7a 100644 --- a/frontend/src/ts/popups/quote-search-popup.ts +++ b/frontend/src/ts/popups/quote-search-popup.ts @@ -13,7 +13,7 @@ import { } from "../utils/search-service"; import { splitByAndKeep } from "../utils/strings"; import QuotesController from "../controllers/quotes-controller"; -import { Auth } from "../firebase"; +import { isAuthenticated } from "../firebase"; import { debounce } from "throttle-debounce"; import Ape from "../ape"; import * as Loader from "../elements/loader"; @@ -117,7 +117,7 @@ function buildQuoteSearchResult( lengthDesc = "thicc"; } - const loggedOut = !Auth?.currentUser; + const loggedOut = !isAuthenticated(); const isFav = !loggedOut && QuotesController.isQuoteFavorite(quote); return ` @@ -219,7 +219,7 @@ export async function show(clearText = true): Promise { const quoteSearchInputValue = $("#quoteSearchPopup input").val() as string; - if (!Auth?.currentUser) { + if (!isAuthenticated()) { $("#quoteSearchPopup #gotoSubmitQuoteButton").addClass("hidden"); $("#quoteSearchPopup #toggleShowFavorites").addClass("hidden"); } else { @@ -454,7 +454,7 @@ $("#popups").on( ); $("#popups").on("click", "#quoteSearchPopup #toggleShowFavorites", (e) => { - if (!Auth?.currentUser) { + if (!isAuthenticated()) { // Notifications.add("You need to be logged in to use this feature!", 0); return; } diff --git a/frontend/src/ts/popups/simple-popups.ts b/frontend/src/ts/popups/simple-popups.ts index ce2b50048..0496e63e4 100644 --- a/frontend/src/ts/popups/simple-popups.ts +++ b/frontend/src/ts/popups/simple-popups.ts @@ -11,7 +11,7 @@ import * as CustomText from "../test/custom-text"; import * as SavedTextsPopup from "./saved-texts-popup"; import * as AccountButton from "../elements/account-button"; import { FirebaseError } from "firebase/app"; -import { Auth } from "../firebase"; +import { Auth, isAuthenticated, getAuthenticatedUser } from "../firebase"; import * as ConnectionState from "../states/connection"; import { EmailAuthProvider, @@ -418,24 +418,24 @@ async function reauthenticate( method: ReauthMethod, password: string ): Promise { - if (!Auth) { + if (Auth === undefined) { return { status: -1, message: "Authentication is not initialized", }; } - const user = Auth.currentUser; - if (!user) { + + if (!isAuthenticated()) { return { status: -1, message: "User is not signed in", }; } + const user = getAuthenticatedUser(); try { - const passwordAuthEnabled = user.providerData.some( - (p) => p?.providerId === "password" - ); + const passwordAuthEnabled = + user.providerData.some((p) => p?.providerId === "password") !== undefined; if (!passwordAuthEnabled && method === "passwordOnly") { return { @@ -472,7 +472,7 @@ async function reauthenticate( status: -1, message: "Failed to reauthenticate: " + - (typedError?.message || JSON.stringify(e)), + (typedError?.message ?? JSON.stringify(e)), }; } } @@ -535,9 +535,8 @@ list.updateEmail = new SimplePopup( }; }, (thisPopup) => { - const user = Auth?.currentUser; - if (!user) return; - if (!user.providerData.find((p) => p?.providerId === "password")) { + if (!isAuthenticated()) return; + if (!isUsingPasswordAuthentication()) { thisPopup.inputs = []; thisPopup.buttonText = ""; thisPopup.text = "Password authentication is not enabled"; @@ -589,9 +588,8 @@ list.removeGoogleAuth = new SimplePopup( }; }, (thisPopup) => { - const user = Auth?.currentUser; - if (!user) return; - if (!user.providerData.find((p) => p?.providerId === "password")) { + if (!isAuthenticated()) return; + if (!isUsingPasswordAuthentication()) { thisPopup.inputs = []; thisPopup.buttonText = ""; thisPopup.text = "Password authentication is not enabled"; @@ -666,10 +664,10 @@ list.updateName = new SimplePopup( }; }, (thisPopup) => { - const user = Auth?.currentUser; + if (!isAuthenticated()) return; const snapshot = DB.getSnapshot(); - if (!user || !snapshot) return; - if (!user.providerData.find((p) => p?.providerId === "password")) { + if (!snapshot) return; + if (!isUsingPasswordAuthentication()) { (thisPopup.inputs[0] as Input).hidden = true; thisPopup.buttonText = "Reauthenticate to update"; } @@ -755,9 +753,8 @@ list.updatePassword = new SimplePopup( }; }, (thisPopup) => { - const user = Auth?.currentUser; - if (!user) return; - if (!user.providerData.find((p) => p?.providerId === "password")) { + if (!isAuthenticated()) return; + if (!isUsingPasswordAuthentication()) { thisPopup.inputs = []; thisPopup.buttonText = ""; thisPopup.text = "Password authentication is not enabled"; @@ -921,9 +918,8 @@ list.deleteAccount = new SimplePopup( }; }, (thisPopup) => { - const user = Auth?.currentUser; - if (!user) return; - if (!user.providerData.find((p) => p?.providerId === "password")) { + if (!isAuthenticated()) return; + if (!isUsingPasswordAuthentication()) { thisPopup.inputs = []; thisPopup.buttonText = "Reauthenticate to delete"; } @@ -975,9 +971,8 @@ list.resetAccount = new SimplePopup( }; }, (thisPopup) => { - const user = Auth?.currentUser; - if (!user) return; - if (!user.providerData.find((p) => p?.providerId === "password")) { + if (!isAuthenticated()) return; + if (!isUsingPasswordAuthentication()) { thisPopup.inputs = []; thisPopup.buttonText = "Reauthenticate to reset"; } @@ -1025,9 +1020,8 @@ list.optOutOfLeaderboards = new SimplePopup( }; }, (thisPopup) => { - const user = Auth?.currentUser; - if (!user) return; - if (!user.providerData.find((p) => p?.providerId === "password")) { + if (!isAuthenticated()) return; + if (!isUsingPasswordAuthentication()) { thisPopup.inputs = []; thisPopup.buttonText = "Reauthenticate to reset"; } @@ -1167,9 +1161,8 @@ list.resetPersonalBests = new SimplePopup( }; }, (thisPopup) => { - const user = Auth?.currentUser; - if (!user) return; - if (!user.providerData.find((p) => p?.providerId === "password")) { + if (!isAuthenticated()) return; + if (!isUsingPasswordAuthentication()) { thisPopup.inputs = []; thisPopup.buttonText = "Reauthenticate to reset"; } @@ -1239,10 +1232,10 @@ list.revokeAllTokens = new SimplePopup( }; }, (thisPopup) => { - const user = Auth?.currentUser; + if (!isAuthenticated()) return; const snapshot = DB.getSnapshot(); - if (!user || !snapshot) return; - if (!user.providerData.find((p) => p?.providerId === "password")) { + if (!snapshot) return; + if (!isUsingPasswordAuthentication()) { (thisPopup.inputs[0] as Input).hidden = true; thisPopup.buttonText = "reauthenticate to revoke all tokens"; } @@ -1895,3 +1888,11 @@ $(document).on("keydown", (event) => { Skeleton.save(wrapperId); console.log(list); + +function isUsingPasswordAuthentication(): boolean { + return ( + Auth?.currentUser?.providerData.find( + (p) => p?.providerId === "password" + ) !== undefined + ); +} diff --git a/frontend/src/ts/settings/theme-picker.ts b/frontend/src/ts/settings/theme-picker.ts index ebfc89c7b..427c9e2ab 100644 --- a/frontend/src/ts/settings/theme-picker.ts +++ b/frontend/src/ts/settings/theme-picker.ts @@ -8,7 +8,7 @@ import * as ShareCustomThemePopup from "../popups/share-custom-theme-popup"; import * as Loader from "../elements/loader"; import * as DB from "../db"; import * as ConfigEvent from "../observables/config-event"; -import { Auth } from "../firebase"; +import { isAuthenticated } from "../firebase"; import * as ActivePage from "../states/active-page"; function updateActiveButton(): void { @@ -118,7 +118,7 @@ export async function refreshButtons(): Promise { ).empty(); const addButton = $(".pageSettings .section.themes .addCustomThemeButton"); - if (!Auth?.currentUser) { + if (!isAuthenticated()) { $( ".pageSettings .section.themes .customThemeEdit #saveCustomThemeButton" ).text("save"); @@ -464,7 +464,7 @@ $("#shareCustomThemeButton").on("click", () => { $(".pageSettings #saveCustomThemeButton").on("click", async () => { saveCustomThemeColors(); - if (Auth?.currentUser) { + if (isAuthenticated()) { const newCustomTheme = { name: "custom", colors: Config.customThemeColors, diff --git a/frontend/src/ts/test/result.ts b/frontend/src/ts/test/result.ts index faf47e432..cc6906164 100644 --- a/frontend/src/ts/test/result.ts +++ b/frontend/src/ts/test/result.ts @@ -7,7 +7,7 @@ import * as DB from "../db"; import * as Loader from "../elements/loader"; import * as Notifications from "../elements/notifications"; import * as ThemeColors from "../elements/theme-colors"; -import { Auth } from "../firebase"; +import { isAuthenticated } from "../firebase"; import * as QuoteRatePopup from "../popups/quote-rate-popup"; import * as GlarsesMode from "../states/glarses-mode"; import * as SlowTimer from "../states/slow-timer"; @@ -689,7 +689,7 @@ export function updateRateQuote(randomQuote: MonkeyTypes.Quote | null): void { function updateQuoteFavorite(randomQuote: MonkeyTypes.Quote | null): void { const icon = $(".pageTest #result #favoriteQuoteButton .icon"); - if (Config.mode !== "quote" || Auth?.currentUser === null) { + if (Config.mode !== "quote" || !isAuthenticated()) { icon.parent().addClass("hidden"); return; } @@ -744,7 +744,7 @@ export async function update( $("#words").removeClass("blurred"); $("#wordsInput").trigger("blur"); $("#result .stats .time .bottom .afk").text(""); - if (Auth?.currentUser) { + if (isAuthenticated()) { $("#result .loginTip").addClass("hidden"); } else { $("#result .loginTip").removeClass("hidden"); @@ -811,7 +811,7 @@ export async function update( $("main #result .stats").removeClass("hidden"); $("main #result .chart").removeClass("hidden"); // $("main #result #resultWordsHistory").removeClass("hidden"); - if (!Auth?.currentUser) { + if (!isAuthenticated()) { $("main #result .loginTip").removeClass("hidden"); } $("main #result #showWordHistoryButton").removeClass("hidden"); diff --git a/frontend/src/ts/test/test-logic.ts b/frontend/src/ts/test/test-logic.ts index 85199fcff..8cc997f90 100644 --- a/frontend/src/ts/test/test-logic.ts +++ b/frontend/src/ts/test/test-logic.ts @@ -46,7 +46,7 @@ import * as Last10Average from "../elements/last-10-average"; import * as Monkey from "./monkey"; import objectHash from "object-hash"; import * as AnalyticsController from "../controllers/analytics-controller"; -import { Auth } from "../firebase"; +import { Auth, isAuthenticated } from "../firebase"; import * as AdController from "../controllers/ad-controller"; import * as TestConfig from "./test-config"; import * as ConnectionState from "../states/connection"; @@ -78,7 +78,7 @@ export function startTest(now: number): boolean { return false; } - if (Auth?.currentUser) { + if (isAuthenticated()) { void AnalyticsController.log("testStarted"); } else { void AnalyticsController.log("testStartedNoLogin"); @@ -459,7 +459,7 @@ export async function init(): Promise { } if (Config.mode === "quote") { - if (Config.quoteLength.includes(-3) && !Auth?.currentUser) { + if (Config.quoteLength.includes(-3) && !isAuthenticated()) { UpdateConfig.setQuoteLength(-1); } } @@ -1086,7 +1086,7 @@ export async function finish(difficultyFailed = false): Promise { Result.updateTodayTracker(); } - if (!Auth?.currentUser) { + if (!isAuthenticated()) { $(".pageTest #result #rateQuoteButton").addClass("hidden"); $(".pageTest #result #reportQuoteButton").addClass("hidden"); void AnalyticsController.log("testCompletedNoLogin"); diff --git a/frontend/src/ts/test/test-ui.ts b/frontend/src/ts/test/test-ui.ts index 13c3fd979..9a0aaac08 100644 --- a/frontend/src/ts/test/test-ui.ts +++ b/frontend/src/ts/test/test-ui.ts @@ -15,7 +15,7 @@ import * as CompositionState from "../states/composition"; import * as ConfigEvent from "../observables/config-event"; import * as Hangul from "hangul-js"; import format from "date-fns/format"; -import { Auth } from "../firebase"; +import { isAuthenticated } from "../firebase"; import { skipXpBreakdown } from "../elements/account-button"; import * as FunboxList from "./funbox/funbox-list"; import { debounce } from "throttle-debounce"; @@ -425,7 +425,7 @@ export async function screenshot(): Promise { $(".highlightContainer").removeClass("hidden"); if (revertCookie) $("#cookiePopupWrapper").removeClass("hidden"); if (revealReplay) $("#resultReplay").removeClass("hidden"); - if (!Auth?.currentUser) { + if (!isAuthenticated()) { $(".pageTest .loginTip").removeClass("hidden"); } (document.querySelector("html") as HTMLElement).style.scrollBehavior = @@ -445,7 +445,7 @@ export async function screenshot(): Promise { $(".pageTest .ssWatermark").text( format(dateNow, "dd MMM yyyy HH:mm") + " | monkeytype.com " ); - if (Auth?.currentUser) { + if (isAuthenticated()) { $(".pageTest .ssWatermark").text( DB.getSnapshot()?.name + " | " +