From 633859f677282289859faee7d38f6859e56e33d1 Mon Sep 17 00:00:00 2001 From: iswilljr Date: Fri, 13 Dec 2024 18:50:06 -0500 Subject: [PATCH] skip anonymous sign in for bots --- package.json | 1 + pnpm-lock.yaml | 178 ++++++++++++++++++++++++++----- src/components/Auth/NavUser.tsx | 4 +- src/components/Home/Header.astro | 4 +- src/hooks/use-session.ts | 7 +- 5 files changed, 164 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index 34aafff..74132e6 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "better-auth": "0.8.2-beta.1", "class-variance-authority": "^0.7.0", "clsx": "^2.1.1", + "isbot": "5.1.17", "lucide-astro": "0.456.0", "lucide-react": "^0.456.0", "nanostores": "^0.11.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9d940bd..9b4456a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -16,13 +16,13 @@ importers: version: 0.14.3(@types/react@18.3.12)(kysely@0.27.4)(react@18.3.1) '@astrojs/react': specifier: ^3.6.2 - version: 3.6.2(@types/react-dom@18.3.1)(@types/react@18.3.12)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(vite@5.4.10(@types/node@16.18.11)(terser@5.36.0)) + version: 3.6.2(@types/react-dom@18.3.1)(@types/react@18.3.12)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(vite@5.4.10(@types/node@16.18.11)(lightningcss@1.27.0)(terser@5.36.0)) '@astrojs/tailwind': specifier: 5.1.2 - version: 5.1.2(astro@4.16.10(@types/node@16.18.11)(rollup@4.22.4)(terser@5.36.0)(typescript@5.6.3))(tailwindcss@3.4.14(ts-node@10.9.1(@types/node@16.18.11)(typescript@5.6.3)))(ts-node@10.9.1(@types/node@16.18.11)(typescript@5.6.3)) + version: 5.1.2(astro@4.16.10(@types/node@16.18.11)(lightningcss@1.27.0)(rollup@4.22.4)(terser@5.36.0)(typescript@5.6.3))(tailwindcss@3.4.14(ts-node@10.9.1(@types/node@16.18.11)(typescript@5.6.3)))(ts-node@10.9.1(@types/node@16.18.11)(typescript@5.6.3)) '@astrojs/vercel': specifier: 7.8.2 - version: 7.8.2(astro@4.16.10(@types/node@16.18.11)(rollup@4.22.4)(terser@5.36.0)(typescript@5.6.3))(react@18.3.1) + version: 7.8.2(astro@4.16.10(@types/node@16.18.11)(lightningcss@1.27.0)(rollup@4.22.4)(terser@5.36.0)(typescript@5.6.3))(react@18.3.1) '@libsql/kysely-libsql': specifier: 0.4.1 version: 0.4.1(kysely@0.27.4) @@ -58,10 +58,10 @@ importers: version: 18.3.1 '@vitejs/plugin-legacy': specifier: 5.4.3 - version: 5.4.3(terser@5.36.0)(vite@5.4.10(@types/node@16.18.11)(terser@5.36.0)) + version: 5.4.3(terser@5.36.0)(vite@5.4.10(@types/node@16.18.11)(lightningcss@1.27.0)(terser@5.36.0)) astro: specifier: 4.16.10 - version: 4.16.10(@types/node@16.18.11)(rollup@4.22.4)(terser@5.36.0)(typescript@5.6.3) + version: 4.16.10(@types/node@16.18.11)(lightningcss@1.27.0)(rollup@4.22.4)(terser@5.36.0)(typescript@5.6.3) better-auth: specifier: 0.8.2-beta.1 version: 0.8.2-beta.1 @@ -71,9 +71,12 @@ importers: clsx: specifier: ^2.1.1 version: 2.1.1 + isbot: + specifier: 5.1.17 + version: 5.1.17 lucide-astro: specifier: 0.456.0 - version: 0.456.0(astro@4.16.10(@types/node@16.18.11)(rollup@4.22.4)(terser@5.36.0)(typescript@5.6.3)) + version: 0.456.0(astro@4.16.10(@types/node@16.18.11)(lightningcss@1.27.0)(rollup@4.22.4)(terser@5.36.0)(typescript@5.6.3)) lucide-react: specifier: ^0.456.0 version: 0.456.0(react@18.3.1) @@ -2765,6 +2768,11 @@ packages: resolution: {integrity: sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==} engines: {node: '>=6'} + detect-libc@1.0.3: + resolution: {integrity: sha512-pGjwhsmsp4kL2RTz08wcOlGN83otlqHeD/Z5T8GXZB+/YcpQ/dgo+lbU8ZsGxV0HIvqqxo9l7mqYwyYMD9bKDg==} + engines: {node: '>=0.10'} + hasBin: true + detect-libc@2.0.2: resolution: {integrity: sha512-UX6sGumvvqSaXgdKGUsgZWqcUyIXZ/vZTrlRT/iobiKhGL0zL4d3osHj3uqllWJK+i+sixDS/3COVEOFbupFyw==} engines: {node: '>=8'} @@ -3786,6 +3794,10 @@ packages: isarray@2.0.5: resolution: {integrity: sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==} + isbot@5.1.17: + resolution: {integrity: sha512-/wch8pRKZE+aoVhRX/hYPY1C7dMCeeMyhkQLNLNlYAbGQn9bkvMB8fOUXNnk5I0m4vDYbBJ9ciVtkr9zfBJ7qA==} + engines: {node: '>=18'} + isexe@2.0.0: resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==} @@ -3880,14 +3892,76 @@ packages: libsql@0.3.19: resolution: {integrity: sha512-Aj5cQ5uk/6fHdmeW0TiXK42FqUlwx7ytmMLPSaUQPin5HKKKuUPD62MAbN4OEweGBBI7q1BekoEN4gPUEL6MZA==} - cpu: [x64, arm64, wasm32] os: [darwin, linux, win32] libsql@0.4.7: resolution: {integrity: sha512-T9eIRCs6b0J1SHKYIvD8+KCJMcWZ900iZyxdnSCdqxN12Z1ijzT+jY5nrk72Jw4B0HGzms2NgpryArlJqvc3Lw==} - cpu: [x64, arm64, wasm32] os: [darwin, linux, win32] + lightningcss-darwin-arm64@1.27.0: + resolution: {integrity: sha512-Gl/lqIXY+d+ySmMbgDf0pgaWSqrWYxVHoc88q+Vhf2YNzZ8DwoRzGt5NZDVqqIW5ScpSnmmjcgXP87Dn2ylSSQ==} + engines: {node: '>= 12.0.0'} + cpu: [arm64] + os: [darwin] + + lightningcss-darwin-x64@1.27.0: + resolution: {integrity: sha512-0+mZa54IlcNAoQS9E0+niovhyjjQWEMrwW0p2sSdLRhLDc8LMQ/b67z7+B5q4VmjYCMSfnFi3djAAQFIDuj/Tg==} + engines: {node: '>= 12.0.0'} + cpu: [x64] + os: [darwin] + + lightningcss-freebsd-x64@1.27.0: + resolution: {integrity: sha512-n1sEf85fePoU2aDN2PzYjoI8gbBqnmLGEhKq7q0DKLj0UTVmOTwDC7PtLcy/zFxzASTSBlVQYJUhwIStQMIpRA==} + engines: {node: '>= 12.0.0'} + cpu: [x64] + os: [freebsd] + + lightningcss-linux-arm-gnueabihf@1.27.0: + resolution: {integrity: sha512-MUMRmtdRkOkd5z3h986HOuNBD1c2lq2BSQA1Jg88d9I7bmPGx08bwGcnB75dvr17CwxjxD6XPi3Qh8ArmKFqCA==} + engines: {node: '>= 12.0.0'} + cpu: [arm] + os: [linux] + + lightningcss-linux-arm64-gnu@1.27.0: + resolution: {integrity: sha512-cPsxo1QEWq2sfKkSq2Bq5feQDHdUEwgtA9KaB27J5AX22+l4l0ptgjMZZtYtUnteBofjee+0oW1wQ1guv04a7A==} + engines: {node: '>= 12.0.0'} + cpu: [arm64] + os: [linux] + + lightningcss-linux-arm64-musl@1.27.0: + resolution: {integrity: sha512-rCGBm2ax7kQ9pBSeITfCW9XSVF69VX+fm5DIpvDZQl4NnQoMQyRwhZQm9pd59m8leZ1IesRqWk2v/DntMo26lg==} + engines: {node: '>= 12.0.0'} + cpu: [arm64] + os: [linux] + + lightningcss-linux-x64-gnu@1.27.0: + resolution: {integrity: sha512-Dk/jovSI7qqhJDiUibvaikNKI2x6kWPN79AQiD/E/KeQWMjdGe9kw51RAgoWFDi0coP4jinaH14Nrt/J8z3U4A==} + engines: {node: '>= 12.0.0'} + cpu: [x64] + os: [linux] + + lightningcss-linux-x64-musl@1.27.0: + resolution: {integrity: sha512-QKjTxXm8A9s6v9Tg3Fk0gscCQA1t/HMoF7Woy1u68wCk5kS4fR+q3vXa1p3++REW784cRAtkYKrPy6JKibrEZA==} + engines: {node: '>= 12.0.0'} + cpu: [x64] + os: [linux] + + lightningcss-win32-arm64-msvc@1.27.0: + resolution: {integrity: sha512-/wXegPS1hnhkeG4OXQKEMQeJd48RDC3qdh+OA8pCuOPCyvnm/yEayrJdJVqzBsqpy1aJklRCVxscpFur80o6iQ==} + engines: {node: '>= 12.0.0'} + cpu: [arm64] + os: [win32] + + lightningcss-win32-x64-msvc@1.27.0: + resolution: {integrity: sha512-/OJLj94Zm/waZShL8nB5jsNj3CfNATLCTyFxZyouilfTmSoLDX7VlVAmhPHoZWVFp4vdmoiEbPEYC8HID3m6yw==} + engines: {node: '>= 12.0.0'} + cpu: [x64] + os: [win32] + + lightningcss@1.27.0: + resolution: {integrity: sha512-8f7aNmS1+etYSLHht0fQApPc2kNO8qGRutifN5rVIc6Xo6ABsEbqOr758UwI7ALVbTt4x1fllKt0PYgzD9S3yQ==} + engines: {node: '>= 12.0.0'} + lilconfig@2.1.0: resolution: {integrity: sha512-utWOt/GHzuUxnLKxB6dk81RoOeoNeHgbrXiuGk4yyF5qlRz+iIVWu56E2fqGHFrXz0QNUhLB/8nKqvRH66JKGQ==} engines: {node: '>=10'} @@ -5790,11 +5864,11 @@ snapshots: dependencies: prismjs: 1.29.0 - '@astrojs/react@3.6.2(@types/react-dom@18.3.1)(@types/react@18.3.12)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(vite@5.4.10(@types/node@16.18.11)(terser@5.36.0))': + '@astrojs/react@3.6.2(@types/react-dom@18.3.1)(@types/react@18.3.12)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(vite@5.4.10(@types/node@16.18.11)(lightningcss@1.27.0)(terser@5.36.0))': dependencies: '@types/react': 18.3.12 '@types/react-dom': 18.3.1 - '@vitejs/plugin-react': 4.3.3(vite@5.4.10(@types/node@16.18.11)(terser@5.36.0)) + '@vitejs/plugin-react': 4.3.3(vite@5.4.10(@types/node@16.18.11)(lightningcss@1.27.0)(terser@5.36.0)) react: 18.3.1 react-dom: 18.3.1(react@18.3.1) ultrahtml: 1.5.3 @@ -5808,9 +5882,9 @@ snapshots: kleur: 4.1.5 ora: 8.1.1 - '@astrojs/tailwind@5.1.2(astro@4.16.10(@types/node@16.18.11)(rollup@4.22.4)(terser@5.36.0)(typescript@5.6.3))(tailwindcss@3.4.14(ts-node@10.9.1(@types/node@16.18.11)(typescript@5.6.3)))(ts-node@10.9.1(@types/node@16.18.11)(typescript@5.6.3))': + '@astrojs/tailwind@5.1.2(astro@4.16.10(@types/node@16.18.11)(lightningcss@1.27.0)(rollup@4.22.4)(terser@5.36.0)(typescript@5.6.3))(tailwindcss@3.4.14(ts-node@10.9.1(@types/node@16.18.11)(typescript@5.6.3)))(ts-node@10.9.1(@types/node@16.18.11)(typescript@5.6.3))': dependencies: - astro: 4.16.10(@types/node@16.18.11)(rollup@4.22.4)(terser@5.36.0)(typescript@5.6.3) + astro: 4.16.10(@types/node@16.18.11)(lightningcss@1.27.0)(rollup@4.22.4)(terser@5.36.0)(typescript@5.6.3) autoprefixer: 10.4.20(postcss@8.4.47) postcss: 8.4.47 postcss-load-config: 4.0.2(postcss@8.4.47)(ts-node@10.9.1(@types/node@16.18.11)(typescript@5.6.3)) @@ -5830,13 +5904,13 @@ snapshots: transitivePeerDependencies: - supports-color - '@astrojs/vercel@7.8.2(astro@4.16.10(@types/node@16.18.11)(rollup@4.22.4)(terser@5.36.0)(typescript@5.6.3))(react@18.3.1)': + '@astrojs/vercel@7.8.2(astro@4.16.10(@types/node@16.18.11)(lightningcss@1.27.0)(rollup@4.22.4)(terser@5.36.0)(typescript@5.6.3))(react@18.3.1)': dependencies: '@astrojs/internal-helpers': 0.4.1 '@vercel/analytics': 1.3.2(react@18.3.1) '@vercel/edge': 1.1.2 '@vercel/nft': 0.27.4 - astro: 4.16.10(@types/node@16.18.11)(rollup@4.22.4)(terser@5.36.0)(typescript@5.6.3) + astro: 4.16.10(@types/node@16.18.11)(lightningcss@1.27.0)(rollup@4.22.4)(terser@5.36.0)(typescript@5.6.3) esbuild: 0.21.5 fast-glob: 3.3.2 web-vitals: 3.5.2 @@ -7993,7 +8067,7 @@ snapshots: json-schema-to-ts: 1.6.4 ts-morph: 12.0.0 - '@vitejs/plugin-legacy@5.4.3(terser@5.36.0)(vite@5.4.10(@types/node@16.18.11)(terser@5.36.0))': + '@vitejs/plugin-legacy@5.4.3(terser@5.36.0)(vite@5.4.10(@types/node@16.18.11)(lightningcss@1.27.0)(terser@5.36.0))': dependencies: '@babel/core': 7.26.0 '@babel/preset-env': 7.26.0(@babel/core@7.26.0) @@ -8004,18 +8078,18 @@ snapshots: regenerator-runtime: 0.14.1 systemjs: 6.15.1 terser: 5.36.0 - vite: 5.4.10(@types/node@16.18.11)(terser@5.36.0) + vite: 5.4.10(@types/node@16.18.11)(lightningcss@1.27.0)(terser@5.36.0) transitivePeerDependencies: - supports-color - '@vitejs/plugin-react@4.3.3(vite@5.4.10(@types/node@16.18.11)(terser@5.36.0))': + '@vitejs/plugin-react@4.3.3(vite@5.4.10(@types/node@16.18.11)(lightningcss@1.27.0)(terser@5.36.0))': dependencies: '@babel/core': 7.25.8 '@babel/plugin-transform-react-jsx-self': 7.25.7(@babel/core@7.25.8) '@babel/plugin-transform-react-jsx-source': 7.25.7(@babel/core@7.25.8) '@types/babel__core': 7.20.5 react-refresh: 0.14.2 - vite: 5.4.10(@types/node@16.18.11)(terser@5.36.0) + vite: 5.4.10(@types/node@16.18.11)(lightningcss@1.27.0)(terser@5.36.0) transitivePeerDependencies: - supports-color @@ -8243,7 +8317,7 @@ snapshots: - supports-color - typescript - astro@4.16.10(@types/node@16.18.11)(rollup@4.22.4)(terser@5.36.0)(typescript@5.6.3): + astro@4.16.10(@types/node@16.18.11)(lightningcss@1.27.0)(rollup@4.22.4)(terser@5.36.0)(typescript@5.6.3): dependencies: '@astrojs/compiler': 2.10.3 '@astrojs/internal-helpers': 0.4.1 @@ -8299,8 +8373,8 @@ snapshots: tsconfck: 3.1.4(typescript@5.6.3) unist-util-visit: 5.0.0 vfile: 6.0.3 - vite: 5.4.10(@types/node@16.18.11)(terser@5.36.0) - vitefu: 1.0.3(vite@5.4.10(@types/node@16.18.11)(terser@5.36.0)) + vite: 5.4.10(@types/node@16.18.11)(lightningcss@1.27.0)(terser@5.36.0) + vitefu: 1.0.3(vite@5.4.10(@types/node@16.18.11)(lightningcss@1.27.0)(terser@5.36.0)) which-pm: 3.0.0 xxhash-wasm: 1.0.2 yargs-parser: 21.1.1 @@ -8718,6 +8792,9 @@ snapshots: dequal@2.0.3: {} + detect-libc@1.0.3: + optional: true + detect-libc@2.0.2: {} detect-libc@2.0.3: {} @@ -9759,6 +9836,8 @@ snapshots: isarray@2.0.5: {} + isbot@5.1.17: {} + isexe@2.0.0: {} jackspeak@2.3.6: @@ -9862,6 +9941,52 @@ snapshots: '@libsql/linux-x64-musl': 0.4.7 '@libsql/win32-x64-msvc': 0.4.7 + lightningcss-darwin-arm64@1.27.0: + optional: true + + lightningcss-darwin-x64@1.27.0: + optional: true + + lightningcss-freebsd-x64@1.27.0: + optional: true + + lightningcss-linux-arm-gnueabihf@1.27.0: + optional: true + + lightningcss-linux-arm64-gnu@1.27.0: + optional: true + + lightningcss-linux-arm64-musl@1.27.0: + optional: true + + lightningcss-linux-x64-gnu@1.27.0: + optional: true + + lightningcss-linux-x64-musl@1.27.0: + optional: true + + lightningcss-win32-arm64-msvc@1.27.0: + optional: true + + lightningcss-win32-x64-msvc@1.27.0: + optional: true + + lightningcss@1.27.0: + dependencies: + detect-libc: 1.0.3 + optionalDependencies: + lightningcss-darwin-arm64: 1.27.0 + lightningcss-darwin-x64: 1.27.0 + lightningcss-freebsd-x64: 1.27.0 + lightningcss-linux-arm-gnueabihf: 1.27.0 + lightningcss-linux-arm64-gnu: 1.27.0 + lightningcss-linux-arm64-musl: 1.27.0 + lightningcss-linux-x64-gnu: 1.27.0 + lightningcss-linux-x64-musl: 1.27.0 + lightningcss-win32-arm64-msvc: 1.27.0 + lightningcss-win32-x64-msvc: 1.27.0 + optional: true + lilconfig@2.1.0: {} lilconfig@3.1.1: {} @@ -9910,9 +10035,9 @@ snapshots: dependencies: yallist: 4.0.0 - lucide-astro@0.456.0(astro@4.16.10(@types/node@16.18.11)(rollup@4.22.4)(terser@5.36.0)(typescript@5.6.3)): + lucide-astro@0.456.0(astro@4.16.10(@types/node@16.18.11)(lightningcss@1.27.0)(rollup@4.22.4)(terser@5.36.0)(typescript@5.6.3)): dependencies: - astro: 4.16.10(@types/node@16.18.11)(rollup@4.22.4)(terser@5.36.0)(typescript@5.6.3) + astro: 4.16.10(@types/node@16.18.11)(lightningcss@1.27.0)(rollup@4.22.4)(terser@5.36.0)(typescript@5.6.3) lucide-react@0.456.0(react@18.3.1): dependencies: @@ -11573,7 +11698,7 @@ snapshots: '@types/unist': 3.0.2 vfile-message: 4.0.2 - vite@5.4.10(@types/node@16.18.11)(terser@5.36.0): + vite@5.4.10(@types/node@16.18.11)(lightningcss@1.27.0)(terser@5.36.0): dependencies: esbuild: 0.21.5 postcss: 8.4.47 @@ -11581,11 +11706,12 @@ snapshots: optionalDependencies: '@types/node': 16.18.11 fsevents: 2.3.3 + lightningcss: 1.27.0 terser: 5.36.0 - vitefu@1.0.3(vite@5.4.10(@types/node@16.18.11)(terser@5.36.0)): + vitefu@1.0.3(vite@5.4.10(@types/node@16.18.11)(lightningcss@1.27.0)(terser@5.36.0)): optionalDependencies: - vite: 5.4.10(@types/node@16.18.11)(terser@5.36.0) + vite: 5.4.10(@types/node@16.18.11)(lightningcss@1.27.0)(terser@5.36.0) volar-service-css@0.0.61(@volar/language-service@2.4.6): dependencies: diff --git a/src/components/Auth/NavUser.tsx b/src/components/Auth/NavUser.tsx index 1b525ae..dcf1e91 100644 --- a/src/components/Auth/NavUser.tsx +++ b/src/components/Auth/NavUser.tsx @@ -14,8 +14,8 @@ async function handleLogout() { window.location.reload() } -export function NavUser() { - const { user, isLoading, isAuthenticated } = useSession() +export function NavUser({ isBot = false }) { + const { user, isLoading, isAuthenticated } = useSession({ isBot }) if (isLoading || !isAuthenticated) { return diff --git a/src/components/Home/Header.astro b/src/components/Home/Header.astro index c465b31..28a8f14 100644 --- a/src/components/Home/Header.astro +++ b/src/components/Home/Header.astro @@ -2,8 +2,10 @@ import { NavUser } from '@/components/Auth/NavUser' import { Search, SearchMobile } from '@/components/Search' import { Search as SearchIcon, Telescope as PopcornIcon } from 'lucide-astro' +import { isbot } from 'isbot' const pathname = Astro.url.pathname +const isBot = isbot(Astro.request.headers.get('user-agent')) || false ---
@@ -36,7 +38,7 @@ const pathname = Astro.url.pathname Explore - +
diff --git a/src/hooks/use-session.ts b/src/hooks/use-session.ts index 77fca14..6fd8a76 100644 --- a/src/hooks/use-session.ts +++ b/src/hooks/use-session.ts @@ -24,10 +24,15 @@ async function updateSession() { $userSession.set(newUserSession) } -export function useSession() { +export function useSession({ isBot = false } = {}) { const userSession = useStore($userSession) useEffect(() => { + if (isBot) { + $userSession.set({ session: null, user: null, status: 'unauthenticated' }) + return + } + if ($userSession.get().status !== 'initial') { return }