From 35e019558fc29ded555cec3d39ec997543d9f2c9 Mon Sep 17 00:00:00 2001 From: Gib Date: Fri, 6 Jun 2025 08:43:18 -0500 Subject: [PATCH] Cleanup. Stuff from yesterday idk --- package.json | 6 +- pnpm-lock.yaml | 230 +++++++++--------- src/app/(auth-pages)/auth/callback/route.ts | 7 +- src/app/(auth-pages)/forgot-password/page.tsx | 110 +++++---- src/app/(auth-pages)/profile/page.tsx | 59 +++-- src/app/(auth-pages)/sign-in/page.tsx | 43 ++-- src/app/(auth-pages)/sign-up/page.tsx | 55 +++-- src/app/layout.tsx | 221 +++++++++++++---- src/components/context/auth.tsx | 174 ++++++------- src/components/default/StatusMessage.tsx | 4 +- .../default/auth/SignInWithApple.tsx | 23 +- .../default/auth/SignInWithMicrosoft.tsx | 24 +- src/components/default/index.tsx | 5 +- .../navigation/auth/AvatarDropdown.tsx | 28 ++- .../default/profile/AvatarUpload.tsx | 70 +++--- .../default/profile/ProfileForm.tsx | 9 +- .../default/profile/ResetPasswordForm.tsx | 11 +- src/lib/actions/auth.ts | 52 ++-- src/lib/actions/public.ts | 2 +- src/lib/actions/storage.ts | 112 ++++----- src/lib/hooks/auth.ts | 55 +++-- src/lib/hooks/public.ts | 2 +- src/lib/hooks/storage.ts | 110 ++++----- src/lib/hooks/useFileUpload.ts | 26 +- .../docker/volumes/functions/hello/index.ts | 11 +- .../docker/volumes/functions/main/index.ts | 80 +++--- src/utils/supabase/middleware.ts | 13 +- src/utils/supabase/server.ts | 2 +- src/utils/utils.ts | 16 -- 29 files changed, 866 insertions(+), 694 deletions(-) delete mode 100644 src/utils/utils.ts diff --git a/package.json b/package.json index 90be871..b638336 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "@radix-ui/react-separator": "^1.1.7", "@radix-ui/react-slot": "^1.2.3", "@supabase/ssr": "^0.6.1", - "@supabase/supabase-js": "^2.49.10", + "@supabase/supabase-js": "^2.50.0", "@t3-oss/env-nextjs": "^0.12.0", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", @@ -35,14 +35,14 @@ "react-dom": "^19.1.0", "react-hook-form": "^7.57.0", "sonner": "^2.0.5", - "zod": "^3.25.51" + "zod": "^3.25.55" }, "devDependencies": { "@eslint/eslintrc": "^3.3.1", "@tailwindcss/postcss": "^4.1.8", "@types/cors": "^2.8.18", "@types/express": "^5.0.2", - "@types/node": "^20.17.57", + "@types/node": "^20.19.0", "@types/react": "^19.1.6", "@types/react-dom": "^19.1.6", "eslint": "^9.28.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a680456..5e1a2cd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -31,13 +31,13 @@ importers: version: 1.2.3(@types/react@19.1.6)(react@19.1.0) '@supabase/ssr': specifier: ^0.6.1 - version: 0.6.1(@supabase/supabase-js@2.49.10) + version: 0.6.1(@supabase/supabase-js@2.50.0) '@supabase/supabase-js': - specifier: ^2.49.10 - version: 2.49.10 + specifier: ^2.50.0 + version: 2.50.0 '@t3-oss/env-nextjs': specifier: ^0.12.0 - version: 0.12.0(typescript@5.8.3)(zod@3.25.51) + version: 0.12.0(typescript@5.8.3)(zod@3.25.55) class-variance-authority: specifier: ^0.7.1 version: 0.7.1 @@ -66,8 +66,8 @@ importers: specifier: ^2.0.5 version: 2.0.5(react-dom@19.1.0(react@19.1.0))(react@19.1.0) zod: - specifier: ^3.25.51 - version: 3.25.51 + specifier: ^3.25.55 + version: 3.25.55 devDependencies: '@eslint/eslintrc': specifier: ^3.3.1 @@ -82,8 +82,8 @@ importers: specifier: ^5.0.2 version: 5.0.2 '@types/node': - specifier: ^20.17.57 - version: 20.17.57 + specifier: ^20.19.0 + version: 20.19.0 '@types/react': specifier: ^19.1.6 version: 19.1.6 @@ -777,8 +777,8 @@ packages: '@standard-schema/utils@0.3.0': resolution: {integrity: sha512-e7Mew686owMaPJVNNLs55PUvgz371nKgwsc4vxE49zsODpJEnxgxRo2y/OKrqueavXgZNMDVj3DdHFlaSAeU8g==} - '@supabase/auth-js@2.69.1': - resolution: {integrity: sha512-FILtt5WjCNzmReeRLq5wRs3iShwmnWgBvxHfqapC/VoljJl+W8hDAyFmf1NVw3zH+ZjZ05AKxiKxVeb0HNWRMQ==} + '@supabase/auth-js@2.70.0': + resolution: {integrity: sha512-BaAK/tOAZFJtzF1sE3gJ2FwTjLf4ky3PSvcvLGEgEmO4BSBkwWKu8l67rLLIBZPDnCyV7Owk2uPyKHa0kj5QGg==} '@supabase/functions-js@2.4.4': resolution: {integrity: sha512-WL2p6r4AXNGwop7iwvul2BvOtuJ1YQy8EbOd0dhG1oN1q8el/BIRSFCFnWAMM/vJJlHWLi4ad22sKbKr9mvjoA==} @@ -801,8 +801,8 @@ packages: '@supabase/storage-js@2.7.1': resolution: {integrity: sha512-asYHcyDR1fKqrMpytAS1zjyEfvxuOIp1CIXX7ji4lHHcJKqyk+sLl/Vxgm4sN6u8zvuUtae9e4kDxQP2qrwWBA==} - '@supabase/supabase-js@2.49.10': - resolution: {integrity: sha512-IRPcIdncuhD2m1eZ2Fkg0S1fq9SXlHfmAetBxPN66kVFtTucR8b01xKuVmKqcIJokB17umMf1bmqyS8yboXGsw==} + '@supabase/supabase-js@2.50.0': + resolution: {integrity: sha512-M1Gd5tPaaghYZ9OjeO1iORRqbTWFEz/cF3pPubRnMPzA+A8SiUsXXWDP+DWsASZcjEcVEcVQIAF38i5wrijYOg==} '@swc/counter@0.1.3': resolution: {integrity: sha512-e2BR4lsJkkRlKZ/qCHPw9ZaSxc0MVUd7gtbtaB7aMvHeJVYe8sOB8DBZkP2DtISHGSku9sCK6T6cnY0CtXrOCQ==} @@ -938,8 +938,8 @@ packages: '@types/cors@2.8.18': resolution: {integrity: sha512-nX3d0sxJW41CqQvfOzVG1NCTXfFDrDWIghCZncpHeWlVFd81zxB/DLhg7avFg6eHLCRX7ckBmoIIcqa++upvJA==} - '@types/estree@1.0.7': - resolution: {integrity: sha512-w28IoSUCJpidD/TGviZwwMJckNESJZXFu7NBZ5YJ4mEUnNraUn9Pm8HSZm/jDF1pDWYKspWE7oVphigUPRakIQ==} + '@types/estree@1.0.8': + resolution: {integrity: sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w==} '@types/express-serve-static-core@5.0.6': resolution: {integrity: sha512-3xhRnjJPkULekpSzgtoNYYcTWgEZkp4myc+Saevii5JPnHNvHMRlBSHDbs7Bh1iPPoVTERHEZXyhyLbMEsExsA==} @@ -959,8 +959,8 @@ packages: '@types/mime@1.3.5': resolution: {integrity: sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w==} - '@types/node@20.17.57': - resolution: {integrity: sha512-f3T4y6VU4fVQDKVqJV4Uppy8c1p/sVvS3peyqxyWnzkqXFJLRU7Y1Bl7rMS1Qe9z0v4M6McY0Fp9yBsgHJUsWQ==} + '@types/node@20.19.0': + resolution: {integrity: sha512-hfrc+1tud1xcdVTABC2JiomZJEklMcXYNTVtZLAeqTVWD+qL5jkHKT+1lOtqDdGxt+mB53DTtiz673vfjU8D1Q==} '@types/phoenix@1.6.6': resolution: {integrity: sha512-PIzZZlEppgrpoT2QgbnDU+MMzuR6BbCjllj0bM70lWoejMeNJAxCchxnv7J3XFkI8MpygtRpzXrIlmWUBclP5A==} @@ -1047,88 +1047,88 @@ packages: resolution: {integrity: sha512-3i8NrFcZeeDHJ+7ZUuDkGT+UHq+XoFGsymNK2jZCOHcfEzRQ0BdpRtdpSx/Iyf3MHLWIcLS0COuOPibKQboIiQ==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} - '@unrs/resolver-binding-darwin-arm64@1.7.9': - resolution: {integrity: sha512-hWbcVTcNqgUirY5DC3heOLrz35D926r2izfxveBmuIgDwx9KkUHfqd93g8PtROJX01lvhmyAc3E09/ma6jhyqQ==} + '@unrs/resolver-binding-darwin-arm64@1.7.11': + resolution: {integrity: sha512-i3/wlWjQJXMh1uiGtiv7k1EYvrrS3L1hdwmWJJiz1D8jWy726YFYPIxQWbEIVPVAgrfRR0XNlLrTQwq17cuCGw==} cpu: [arm64] os: [darwin] - '@unrs/resolver-binding-darwin-x64@1.7.9': - resolution: {integrity: sha512-NCZb/oaXELjt8jtm6ztlNPpAxKZsKIxsGYPSxkwQdQ/zl7X2PfyCpWqwoGE4A9vCP6gAgJnvH3e22nE0qk9ieA==} + '@unrs/resolver-binding-darwin-x64@1.7.11': + resolution: {integrity: sha512-8XXyFvc6w6kmMmi6VYchZhjd5CDcp+Lv6Cn1YmUme0ypsZ/0Kzd+9ESrWtDrWibKPTgSteDTxp75cvBOY64FQQ==} cpu: [x64] os: [darwin] - '@unrs/resolver-binding-freebsd-x64@1.7.9': - resolution: {integrity: sha512-/AYheGgFn9Pw3X3pYFCohznydaUA9980/wlwgbgCsVxnY4IbqVoZhTLQZ4JWKKaOWBwwmM8FseHf5h5OawyOQQ==} + '@unrs/resolver-binding-freebsd-x64@1.7.11': + resolution: {integrity: sha512-0qJBYzP8Qk24CZ05RSWDQUjdiQUeIJGfqMMzbtXgCKl/a5xa6thfC0MQkGIr55LCLd6YmMyO640ifYUa53lybQ==} cpu: [x64] os: [freebsd] - '@unrs/resolver-binding-linux-arm-gnueabihf@1.7.9': - resolution: {integrity: sha512-RYV9sEH3o6SZum5wGb9evXlgibsVfluuiyi09hXVD+qPRrCSB45h3z1HjZpe9+c25GiN53CEy149fYS0fLVBtw==} + '@unrs/resolver-binding-linux-arm-gnueabihf@1.7.11': + resolution: {integrity: sha512-1sGwpgvx+WZf0GFT6vkkOm6UJ+mlsVnjw+Yv9esK71idWeRAG3bbpkf3AoY8KIqKqmnzJExi0uKxXpakQ5Pcbg==} cpu: [arm] os: [linux] - '@unrs/resolver-binding-linux-arm-musleabihf@1.7.9': - resolution: {integrity: sha512-0ishMZMCYNJd4SNjHnjByHWh6ia7EDVZrOVAW8wf9Vz2PTZ0pLrFwu5c9voHouGKg7s2cnzPz87c0OK7dwimUQ==} + '@unrs/resolver-binding-linux-arm-musleabihf@1.7.11': + resolution: {integrity: sha512-D/1F/2lTe+XAl3ohkYj51NjniVly8sIqkA/n1aOND3ZMO418nl2JNU95iVa1/RtpzaKcWEsNTtHRogykrUflJg==} cpu: [arm] os: [linux] - '@unrs/resolver-binding-linux-arm64-gnu@1.7.9': - resolution: {integrity: sha512-FOspRldYylONzWCkF5n/B1MMYKXXlg2bzgcgESEVcP4LFh0eom/0XsWvfy+dlfBJ+FkYfJjvBJeje14xOBOa6g==} + '@unrs/resolver-binding-linux-arm64-gnu@1.7.11': + resolution: {integrity: sha512-7vFWHLCCNFLEQlmwKQfVy066ohLLArZl+AV/AdmrD1/pD1FlmqM+FKbtnONnIwbHtgetFUCV/SRi1q4D49aTlw==} cpu: [arm64] os: [linux] - '@unrs/resolver-binding-linux-arm64-musl@1.7.9': - resolution: {integrity: sha512-P1S5jTht888/1mZVrBZx8IOxpikRDPoECxod1CcAHYUZGUNr+PNp1m5eB9FWMK2zRCJ8HgHNZfdRyDf9pNCrlQ==} + '@unrs/resolver-binding-linux-arm64-musl@1.7.11': + resolution: {integrity: sha512-tYkGIx8hjWPh4zcn17jLEHU8YMmdP2obRTGkdaB3BguGHh31VCS3ywqC4QjTODjmhhNyZYkj/1Dz/+0kKvg9YA==} cpu: [arm64] os: [linux] - '@unrs/resolver-binding-linux-ppc64-gnu@1.7.9': - resolution: {integrity: sha512-cD9+BPxlFSiIkGWknSgKdTMGZIzCtSIg/O7GJ1LoC+jGtUOBNBJYMn6FyEPRvdpphewYzaCuPsikrMkpdX303Q==} + '@unrs/resolver-binding-linux-ppc64-gnu@1.7.11': + resolution: {integrity: sha512-6F328QIUev29vcZeRX6v6oqKxfUoGwIIAhWGD8wSysnBYFY0nivp25jdWmAb1GildbCCaQvOKEhCok7YfWkj4Q==} cpu: [ppc64] os: [linux] - '@unrs/resolver-binding-linux-riscv64-gnu@1.7.9': - resolution: {integrity: sha512-Z6IuWg9u0257dCVgc/x/zIKamqJhrmaOFuq3AYsSt6ZtyEHoyD5kxdXQUvEgBAd/Fn1b8tsX+VD9mB9al5306Q==} + '@unrs/resolver-binding-linux-riscv64-gnu@1.7.11': + resolution: {integrity: sha512-NqhWmiGJGdzbZbeucPZIG9Iav4lyYLCarEnxAceguMx9qlpeEF7ENqYKOwB8Zqk7/CeuYMEcLYMaW2li6HyDzQ==} cpu: [riscv64] os: [linux] - '@unrs/resolver-binding-linux-riscv64-musl@1.7.9': - resolution: {integrity: sha512-HpINrXLJVEpvkHHIla6pqhMAKbQBrY+2946i6rF6OlByONLTuObg65bcv3A38qV9yqJ7vtE0FyfNn68k0uQKbg==} + '@unrs/resolver-binding-linux-riscv64-musl@1.7.11': + resolution: {integrity: sha512-J2RPIFKMdTrLtBdfR1cUMKl8Gcy05nlQ+bEs/6al7EdWLk9cs3tnDREHZ7mV9uGbeghpjo4i8neNZNx3PYUY9w==} cpu: [riscv64] os: [linux] - '@unrs/resolver-binding-linux-s390x-gnu@1.7.9': - resolution: {integrity: sha512-ZXZFfaPFXnrDIPpkFoAZmxzXwqqfCHfnFdZhrEd+mrc/hHTQyxINyzrFMFCqtAa5eIjD7vgzNIXsMFU2QBnCPw==} + '@unrs/resolver-binding-linux-s390x-gnu@1.7.11': + resolution: {integrity: sha512-bDpGRerHvvHdhun7MmFUNDpMiYcJSqWckwAVVRTJf8F+RyqYJOp/mx04PDc7DhpNPeWdnTMu91oZRMV+gGaVcQ==} cpu: [s390x] os: [linux] - '@unrs/resolver-binding-linux-x64-gnu@1.7.9': - resolution: {integrity: sha512-EzeeaZnuQOa93ox08oa9DqgQc8sK59jfs+apOUrZZSJCDG1ZbtJINPc8uRqE7p3Z66FPAe/uO3+7jZTkWbVDfg==} + '@unrs/resolver-binding-linux-x64-gnu@1.7.11': + resolution: {integrity: sha512-G9U7bVmylzRLma3cK39RBm3guoD1HOvY4o0NS4JNm37AD0lS7/xyMt7kn0JejYyc0Im8J+rH69/dXGM9DAJcSQ==} cpu: [x64] os: [linux] - '@unrs/resolver-binding-linux-x64-musl@1.7.9': - resolution: {integrity: sha512-a07ezNt0OY8Vv/iDreJo7ZkKtwRb6UCYaCcMY2nm3ext7rTtDFS7X1GePqrbByvIbRFd6E5q1CKBPzJk6M360Q==} + '@unrs/resolver-binding-linux-x64-musl@1.7.11': + resolution: {integrity: sha512-7qL20SBKomekSunm7M9Fe5L93bFbn+FbHiGJbfTlp0RKhPVoJDP73vOxf1QrmJHyDPECsGWPFnKa/f8fO2FsHw==} cpu: [x64] os: [linux] - '@unrs/resolver-binding-wasm32-wasi@1.7.9': - resolution: {integrity: sha512-d0fHnxgtrv75Po6LKJLjo1LFC5S0E8vv86H/5wGDFLG0AvS/0k+SghgUW6zAzjM2XRAic/qcy9+O7n/5JOjxFA==} + '@unrs/resolver-binding-wasm32-wasi@1.7.11': + resolution: {integrity: sha512-jisvIva8MidjI+B1lFRZZMfCPaCISePgTyR60wNT1MeQvIh5Ksa0G3gvI+Iqyj3jqYbvOHByenpa5eDGcSdoSg==} engines: {node: '>=14.0.0'} cpu: [wasm32] - '@unrs/resolver-binding-win32-arm64-msvc@1.7.9': - resolution: {integrity: sha512-0MFcaQDsUYxNqRxjPdsMKg1OGtmsqLzPY2Nwiiyalx6HFvkcHxgRCAOppgeUuDucpUEf76k/4tBzfzPxjYkFUg==} + '@unrs/resolver-binding-win32-arm64-msvc@1.7.11': + resolution: {integrity: sha512-G+H5nQZ8sRZ8ebMY6mRGBBvTEzMYEcgVauLsNHpvTUavZoCCRVP1zWkCZgOju2dW3O22+8seTHniTdl1/uLz3g==} cpu: [arm64] os: [win32] - '@unrs/resolver-binding-win32-ia32-msvc@1.7.9': - resolution: {integrity: sha512-SiewmebiN32RpzrV1Dvbw7kdDCRuPThdgEWKJvDNcEGnVEV3ScYGuk5smJjKHXszqNX3mIXG/PcCXqHsE/7XGA==} + '@unrs/resolver-binding-win32-ia32-msvc@1.7.11': + resolution: {integrity: sha512-Hfy46DBfFzyv0wgR0MMOwFFib2W2+Btc8oE5h4XlPhpelnSyA6nFxkVIyTgIXYGTdFaLoZFNn62fmqx3rjEg3A==} cpu: [ia32] os: [win32] - '@unrs/resolver-binding-win32-x64-msvc@1.7.9': - resolution: {integrity: sha512-hORofIRZCm85+TUZ9OmHQJNlgtOmK/TPfvYeSplKAl+zQvAwMGyy6DZcSbrF+KdB1EDoGISwU7dX7PE92haOXg==} + '@unrs/resolver-binding-win32-x64-msvc@1.7.11': + resolution: {integrity: sha512-7L8NdsQlCJ8T106Gbz/AjzM4QKWVsoQbKpB9bMBGcIZswUuAnJMHpvbqGW3RBqLHCIwX4XZ5fxSBHEFcK2h9wA==} cpu: [x64] os: [win32] @@ -2442,11 +2442,11 @@ packages: resolution: {integrity: sha512-nWJ91DjeOkej/TA8pXQ3myruKpKEYgqvpw9lz4OPHj/NWFNluYrjbz9j01CJ8yKQd2g4jFoOkINCTW2I5LEEyw==} engines: {node: '>= 0.4'} - undici-types@6.19.8: - resolution: {integrity: sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==} + undici-types@6.21.0: + resolution: {integrity: sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==} - unrs-resolver@1.7.9: - resolution: {integrity: sha512-hhFtY782YKwpz54G1db49YYS1RuMn8mBylIrCldrjb9BxZKnQ2xHw7+2zcl7H6fnUlTHGWv23/+677cpufhfxQ==} + unrs-resolver@1.7.11: + resolution: {integrity: sha512-OhuAzBImFPjKNgZ2JwHMfGFUA6NSbRegd1+BPjC1Y0E6X9Y/vJ4zKeGmIMqmlYboj6cMNEwKI+xQisrg4J0HaQ==} uri-js@4.4.1: resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==} @@ -2527,8 +2527,8 @@ packages: resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==} engines: {node: '>=10'} - zod@3.25.51: - resolution: {integrity: sha512-TQSnBldh+XSGL+opiSIq0575wvDPqu09AqWe1F7JhUMKY+M91/aGlK4MhpVNO7MgYfHcVCB1ffwAUTJzllKJqg==} + zod@3.25.55: + resolution: {integrity: sha512-219huNnkSLQnLsQ3uaRjXsxMrVm5C9W3OOpEVt2k5tvMKuA8nBSu38e0B//a+he9Iq2dvmk2VyYVlHqiHa4YBA==} snapshots: @@ -3093,7 +3093,7 @@ snapshots: '@standard-schema/utils@0.3.0': {} - '@supabase/auth-js@2.69.1': + '@supabase/auth-js@2.70.0': dependencies: '@supabase/node-fetch': 2.6.15 @@ -3119,18 +3119,18 @@ snapshots: - bufferutil - utf-8-validate - '@supabase/ssr@0.6.1(@supabase/supabase-js@2.49.10)': + '@supabase/ssr@0.6.1(@supabase/supabase-js@2.50.0)': dependencies: - '@supabase/supabase-js': 2.49.10 + '@supabase/supabase-js': 2.50.0 cookie: 1.0.2 '@supabase/storage-js@2.7.1': dependencies: '@supabase/node-fetch': 2.6.15 - '@supabase/supabase-js@2.49.10': + '@supabase/supabase-js@2.50.0': dependencies: - '@supabase/auth-js': 2.69.1 + '@supabase/auth-js': 2.70.0 '@supabase/functions-js': 2.4.4 '@supabase/node-fetch': 2.6.15 '@supabase/postgrest-js': 1.19.4 @@ -3146,17 +3146,17 @@ snapshots: dependencies: tslib: 2.8.1 - '@t3-oss/env-core@0.12.0(typescript@5.8.3)(zod@3.25.51)': + '@t3-oss/env-core@0.12.0(typescript@5.8.3)(zod@3.25.55)': optionalDependencies: typescript: 5.8.3 - zod: 3.25.51 + zod: 3.25.55 - '@t3-oss/env-nextjs@0.12.0(typescript@5.8.3)(zod@3.25.51)': + '@t3-oss/env-nextjs@0.12.0(typescript@5.8.3)(zod@3.25.55)': dependencies: - '@t3-oss/env-core': 0.12.0(typescript@5.8.3)(zod@3.25.51) + '@t3-oss/env-core': 0.12.0(typescript@5.8.3)(zod@3.25.55) optionalDependencies: typescript: 5.8.3 - zod: 3.25.51 + zod: 3.25.55 '@tailwindcss/node@4.1.8': dependencies: @@ -3238,21 +3238,21 @@ snapshots: '@types/body-parser@1.19.5': dependencies: '@types/connect': 3.4.38 - '@types/node': 20.17.57 + '@types/node': 20.19.0 '@types/connect@3.4.38': dependencies: - '@types/node': 20.17.57 + '@types/node': 20.19.0 '@types/cors@2.8.18': dependencies: - '@types/node': 20.17.57 + '@types/node': 20.19.0 - '@types/estree@1.0.7': {} + '@types/estree@1.0.8': {} '@types/express-serve-static-core@5.0.6': dependencies: - '@types/node': 20.17.57 + '@types/node': 20.19.0 '@types/qs': 6.14.0 '@types/range-parser': 1.2.7 '@types/send': 0.17.4 @@ -3271,9 +3271,9 @@ snapshots: '@types/mime@1.3.5': {} - '@types/node@20.17.57': + '@types/node@20.19.0': dependencies: - undici-types: 6.19.8 + undici-types: 6.21.0 '@types/phoenix@1.6.6': {} @@ -3292,17 +3292,17 @@ snapshots: '@types/send@0.17.4': dependencies: '@types/mime': 1.3.5 - '@types/node': 20.17.57 + '@types/node': 20.19.0 '@types/serve-static@1.15.7': dependencies: '@types/http-errors': 2.0.4 - '@types/node': 20.17.57 + '@types/node': 20.19.0 '@types/send': 0.17.4 '@types/ws@8.18.1': dependencies: - '@types/node': 20.17.57 + '@types/node': 20.19.0 '@typescript-eslint/eslint-plugin@8.33.1(@typescript-eslint/parser@8.33.1(eslint@9.28.0(jiti@2.4.2))(typescript@5.8.3))(eslint@9.28.0(jiti@2.4.2))(typescript@5.8.3)': dependencies: @@ -3396,57 +3396,57 @@ snapshots: '@typescript-eslint/types': 8.33.1 eslint-visitor-keys: 4.2.0 - '@unrs/resolver-binding-darwin-arm64@1.7.9': + '@unrs/resolver-binding-darwin-arm64@1.7.11': optional: true - '@unrs/resolver-binding-darwin-x64@1.7.9': + '@unrs/resolver-binding-darwin-x64@1.7.11': optional: true - '@unrs/resolver-binding-freebsd-x64@1.7.9': + '@unrs/resolver-binding-freebsd-x64@1.7.11': optional: true - '@unrs/resolver-binding-linux-arm-gnueabihf@1.7.9': + '@unrs/resolver-binding-linux-arm-gnueabihf@1.7.11': optional: true - '@unrs/resolver-binding-linux-arm-musleabihf@1.7.9': + '@unrs/resolver-binding-linux-arm-musleabihf@1.7.11': optional: true - '@unrs/resolver-binding-linux-arm64-gnu@1.7.9': + '@unrs/resolver-binding-linux-arm64-gnu@1.7.11': optional: true - '@unrs/resolver-binding-linux-arm64-musl@1.7.9': + '@unrs/resolver-binding-linux-arm64-musl@1.7.11': optional: true - '@unrs/resolver-binding-linux-ppc64-gnu@1.7.9': + '@unrs/resolver-binding-linux-ppc64-gnu@1.7.11': optional: true - '@unrs/resolver-binding-linux-riscv64-gnu@1.7.9': + '@unrs/resolver-binding-linux-riscv64-gnu@1.7.11': optional: true - '@unrs/resolver-binding-linux-riscv64-musl@1.7.9': + '@unrs/resolver-binding-linux-riscv64-musl@1.7.11': optional: true - '@unrs/resolver-binding-linux-s390x-gnu@1.7.9': + '@unrs/resolver-binding-linux-s390x-gnu@1.7.11': optional: true - '@unrs/resolver-binding-linux-x64-gnu@1.7.9': + '@unrs/resolver-binding-linux-x64-gnu@1.7.11': optional: true - '@unrs/resolver-binding-linux-x64-musl@1.7.9': + '@unrs/resolver-binding-linux-x64-musl@1.7.11': optional: true - '@unrs/resolver-binding-wasm32-wasi@1.7.9': + '@unrs/resolver-binding-wasm32-wasi@1.7.11': dependencies: '@napi-rs/wasm-runtime': 0.2.10 optional: true - '@unrs/resolver-binding-win32-arm64-msvc@1.7.9': + '@unrs/resolver-binding-win32-arm64-msvc@1.7.11': optional: true - '@unrs/resolver-binding-win32-ia32-msvc@1.7.9': + '@unrs/resolver-binding-win32-ia32-msvc@1.7.11': optional: true - '@unrs/resolver-binding-win32-x64-msvc@1.7.9': + '@unrs/resolver-binding-win32-x64-msvc@1.7.11': optional: true acorn-jsx@5.3.2(acorn@8.14.1): @@ -3841,7 +3841,7 @@ snapshots: is-bun-module: 2.0.0 stable-hash: 0.0.5 tinyglobby: 0.2.14 - unrs-resolver: 1.7.9 + unrs-resolver: 1.7.11 optionalDependencies: eslint-plugin-import: 2.31.0(@typescript-eslint/parser@8.33.1(eslint@9.28.0(jiti@2.4.2))(typescript@5.8.3))(eslint-import-resolver-typescript@3.10.1)(eslint@9.28.0(jiti@2.4.2)) transitivePeerDependencies: @@ -3954,7 +3954,7 @@ snapshots: '@humanfs/node': 0.16.6 '@humanwhocodes/module-importer': 1.0.1 '@humanwhocodes/retry': 0.4.3 - '@types/estree': 1.0.7 + '@types/estree': 1.0.8 '@types/json-schema': 7.0.15 ajv: 6.12.6 chalk: 4.1.2 @@ -4945,29 +4945,29 @@ snapshots: has-symbols: 1.1.0 which-boxed-primitive: 1.1.1 - undici-types@6.19.8: {} + undici-types@6.21.0: {} - unrs-resolver@1.7.9: + unrs-resolver@1.7.11: dependencies: napi-postinstall: 0.2.4 optionalDependencies: - '@unrs/resolver-binding-darwin-arm64': 1.7.9 - '@unrs/resolver-binding-darwin-x64': 1.7.9 - '@unrs/resolver-binding-freebsd-x64': 1.7.9 - '@unrs/resolver-binding-linux-arm-gnueabihf': 1.7.9 - '@unrs/resolver-binding-linux-arm-musleabihf': 1.7.9 - '@unrs/resolver-binding-linux-arm64-gnu': 1.7.9 - '@unrs/resolver-binding-linux-arm64-musl': 1.7.9 - '@unrs/resolver-binding-linux-ppc64-gnu': 1.7.9 - '@unrs/resolver-binding-linux-riscv64-gnu': 1.7.9 - '@unrs/resolver-binding-linux-riscv64-musl': 1.7.9 - '@unrs/resolver-binding-linux-s390x-gnu': 1.7.9 - '@unrs/resolver-binding-linux-x64-gnu': 1.7.9 - '@unrs/resolver-binding-linux-x64-musl': 1.7.9 - '@unrs/resolver-binding-wasm32-wasi': 1.7.9 - '@unrs/resolver-binding-win32-arm64-msvc': 1.7.9 - '@unrs/resolver-binding-win32-ia32-msvc': 1.7.9 - '@unrs/resolver-binding-win32-x64-msvc': 1.7.9 + '@unrs/resolver-binding-darwin-arm64': 1.7.11 + '@unrs/resolver-binding-darwin-x64': 1.7.11 + '@unrs/resolver-binding-freebsd-x64': 1.7.11 + '@unrs/resolver-binding-linux-arm-gnueabihf': 1.7.11 + '@unrs/resolver-binding-linux-arm-musleabihf': 1.7.11 + '@unrs/resolver-binding-linux-arm64-gnu': 1.7.11 + '@unrs/resolver-binding-linux-arm64-musl': 1.7.11 + '@unrs/resolver-binding-linux-ppc64-gnu': 1.7.11 + '@unrs/resolver-binding-linux-riscv64-gnu': 1.7.11 + '@unrs/resolver-binding-linux-riscv64-musl': 1.7.11 + '@unrs/resolver-binding-linux-s390x-gnu': 1.7.11 + '@unrs/resolver-binding-linux-x64-gnu': 1.7.11 + '@unrs/resolver-binding-linux-x64-musl': 1.7.11 + '@unrs/resolver-binding-wasm32-wasi': 1.7.11 + '@unrs/resolver-binding-win32-arm64-msvc': 1.7.11 + '@unrs/resolver-binding-win32-ia32-msvc': 1.7.11 + '@unrs/resolver-binding-win32-x64-msvc': 1.7.11 uri-js@4.4.1: dependencies: @@ -5052,4 +5052,4 @@ snapshots: yocto-queue@0.1.0: {} - zod@3.25.51: {} + zod@3.25.55: {} diff --git a/src/app/(auth-pages)/auth/callback/route.ts b/src/app/(auth-pages)/auth/callback/route.ts index 24089c1..a2a9cec 100644 --- a/src/app/(auth-pages)/auth/callback/route.ts +++ b/src/app/(auth-pages)/auth/callback/route.ts @@ -36,10 +36,11 @@ export const GET = async (request: NextRequest) => { return redirect('/'); if (type === 'recovery' || type === 'email_change') return redirect('/profile'); - if (type === 'invite') - return redirect('/sign-up'); + if (type === 'invite') return redirect('/sign-up'); } - return redirect(`/?error=${encodeURIComponent(error?.message || 'Unknown error')}`); + return redirect( + `/?error=${encodeURIComponent(error?.message || 'Unknown error')}`, + ); } return redirect('/'); diff --git a/src/app/(auth-pages)/forgot-password/page.tsx b/src/app/(auth-pages)/forgot-password/page.tsx index 721f4de..ccbbce6 100644 --- a/src/app/(auth-pages)/forgot-password/page.tsx +++ b/src/app/(auth-pages)/forgot-password/page.tsx @@ -27,7 +27,7 @@ const formSchema = z.object({ email: z.string().email({ message: 'Please enter a valid email address.', }), -}) +}); const ForgotPassword = () => { const router = useRouter(); @@ -48,76 +48,82 @@ const ForgotPassword = () => { } }, [isAuthenticated, router]); - const handleForgotPassword = async (values: z.infer) => { try { setStatusMessage(''); - const formData = new FormData(); + const formData = new FormData(); formData.append('email', values.email); const result = await forgotPassword(formData); if (result?.success) { await refreshUserData(); - setStatusMessage(result?.data ?? 'Check your email for a link to reset your password.') + setStatusMessage( + result?.data ?? 'Check your email for a link to reset your password.', + ); form.reset(); router.push(''); } else { - setStatusMessage(`Error: ${result.error}`) + setStatusMessage(`Error: ${result.error}`); } } catch (error) { setStatusMessage( - `Error: ${error instanceof Error ? error.message : 'Could not sign in!'}` + `Error: ${error instanceof Error ? error.message : 'Could not sign in!'}`, ); } }; return ( - - - Reset Password - - Don't have an account?{' '} - - Sign up - - - - -
- - ( - - Email - - - - - - )} - /> - - Reset Password - - {statusMessage && ( - statusMessage.includes('Error') || - statusMessage.includes('error') || - statusMessage.includes('failed') || - statusMessage.includes('invalid') - ? - : + + + Reset Password + + Don't have an account?{' '} + + Sign up + + + + + + + ( + + Email + + + + + )} - - - - + /> + + Reset Password + + {statusMessage && + (statusMessage.includes('Error') || + statusMessage.includes('error') || + statusMessage.includes('failed') || + statusMessage.includes('invalid') ? ( + + ) : ( + + ))} + + +
+
); }; export default ForgotPassword; diff --git a/src/app/(auth-pages)/profile/page.tsx b/src/app/(auth-pages)/profile/page.tsx index acd5341..75c7dc9 100644 --- a/src/app/(auth-pages)/profile/page.tsx +++ b/src/app/(auth-pages)/profile/page.tsx @@ -2,7 +2,12 @@ import { useAuth } from '@/components/context/auth'; import { useRouter } from 'next/navigation'; import { useEffect } from 'react'; -import { AvatarUpload, ProfileForm, ResetPasswordForm, SignOut } from '@/components/default/profile'; +import { + AvatarUpload, + ProfileForm, + ResetPasswordForm, + SignOut, +} from '@/components/default/profile'; import { Card, CardHeader, @@ -16,14 +21,20 @@ import { toast } from 'sonner'; import { type Result } from '@/lib/actions'; const ProfilePage = () => { - const { profile, isLoading, isAuthenticated, updateProfile, refreshUserData } = useAuth(); + const { + profile, + isLoading, + isAuthenticated, + updateProfile, + refreshUserData, + } = useAuth(); const router = useRouter(); useEffect(() => { if (!isLoading && !isAuthenticated) { router.push('/sign-in'); } - }, [isLoading, isAuthenticated, router]) + }, [isLoading, isAuthenticated, router]); const handleAvatarUploaded = async (path: string) => { await updateProfile({ avatar_url: path }); @@ -50,17 +61,17 @@ const ProfilePage = () => { try { const result = await resetPassword(formData); if (!result.success) { - toast.error(`Error resetting password: ${result.error}`) - return {success: false, error: result.error}; + toast.error(`Error resetting password: ${result.error}`); + return { success: false, error: result.error }; } - return {success: true, data: null}; + return { success: true, data: null }; } catch (error) { toast.error( - `Error resetting password!: ${error as string ?? 'Unknown error'}` + `Error resetting password!: ${(error as string) ?? 'Unknown error'}`, ); - return {success: false, error: 'Unknown error'}; + return { success: false, error: 'Unknown error' }; } - } + }; // Show loading state while checking authentication if (isLoading) { @@ -89,21 +100,21 @@ const ProfilePage = () => { Manage your personal information and how it appears to others - {isLoading && !profile ? ( -
- -
- ) : ( -
- - - - - - - -
- )} + {isLoading && !profile ? ( +
+ +
+ ) : ( +
+ + + + + + + +
+ )} ); diff --git a/src/app/(auth-pages)/sign-in/page.tsx b/src/app/(auth-pages)/sign-in/page.tsx index c554542..6acc617 100644 --- a/src/app/(auth-pages)/sign-in/page.tsx +++ b/src/app/(auth-pages)/sign-in/page.tsx @@ -34,7 +34,7 @@ const formSchema = z.object({ password: z.string().min(8, { message: 'Password must be at least 8 characters.', }), -}) +}); const Login = () => { const router = useRouter(); @@ -59,7 +59,7 @@ const Login = () => { const handleSignIn = async (values: z.infer) => { try { setStatusMessage(''); - const formData = new FormData(); + const formData = new FormData(); formData.append('email', values.email); formData.append('password', values.password); const result = await signIn(formData); @@ -68,11 +68,11 @@ const Login = () => { form.reset(); router.push(''); } else { - setStatusMessage(`Error: ${result.error}`) + setStatusMessage(`Error: ${result.error}`); } } catch (error) { setStatusMessage( - `Error: ${error instanceof Error ? error.message : 'Could not sign in!'}` + `Error: ${error instanceof Error ? error.message : 'Could not sign in!'}`, ); } }; @@ -80,9 +80,7 @@ const Login = () => { return ( - - Sign In - + Sign In Don't have an account?{' '} @@ -103,11 +101,15 @@ const Login = () => { Email - + - )} + )} /> { - + )} /> - {statusMessage && ( - statusMessage.includes('Error') || - statusMessage.includes('error') || - statusMessage.includes('failed') || - statusMessage.includes('invalid') - ? - : - )} + {statusMessage && + (statusMessage.includes('Error') || + statusMessage.includes('error') || + statusMessage.includes('failed') || + statusMessage.includes('invalid') ? ( + + ) : ( + + ))} { - const router = useRouter(); const { isAuthenticated, isLoading, refreshUserData } = useAuth(); const [statusMessage, setStatusMessage] = useState(''); @@ -71,7 +70,7 @@ const SignUp = () => { const handleSignUp = async (values: z.infer) => { try { setStatusMessage(''); - const formData = new FormData(); + const formData = new FormData(); formData.append('name', values.name); formData.append('email', values.email); formData.append('password', values.password); @@ -80,16 +79,16 @@ const SignUp = () => { await refreshUserData(); setStatusMessage( result.data ?? - 'Thanks for signing up! Please check your email for a verification link.' + 'Thanks for signing up! Please check your email for a verification link.', ); form.reset(); router.push(''); } else { - setStatusMessage(`Error: ${result.error}`) + setStatusMessage(`Error: ${result.error}`); } } catch (error) { setStatusMessage( - `Error: ${error instanceof Error ? error.message : 'Could not sign in!'}` + `Error: ${error instanceof Error ? error.message : 'Could not sign in!'}`, ); } }; @@ -97,9 +96,7 @@ const SignUp = () => { return ( - - Sign Up - + Sign Up Already have an account?{' '} @@ -109,7 +106,10 @@ const SignUp = () => {
- + { Email - + - )} + )} /> { Password - + @@ -155,20 +163,25 @@ const SignUp = () => { Confirm Password - + )} /> - {statusMessage && ( - statusMessage.includes('Error') || - statusMessage.includes('error') || - statusMessage.includes('failed') || - statusMessage.includes('invalid') - ? - : - )} + {statusMessage && + (statusMessage.includes('Error') || + statusMessage.includes('error') || + statusMessage.includes('failed') || + statusMessage.includes('invalid') ? ( + + ) : ( + + ))} { const [isInitialized, setIsInitialized] = useState(false); const fetchingRef = useRef(false); - const fetchUserData = useCallback(async (showLoading = true) => { - if (fetchingRef.current) return; - fetchingRef.current = true; + const fetchUserData = useCallback( + async (showLoading = true) => { + if (fetchingRef.current) return; + fetchingRef.current = true; - try { - // Only show loading for initial load or manual refresh - if (showLoading) { - setIsLoading(true); - } + try { + // Only show loading for initial load or manual refresh + if (showLoading) { + setIsLoading(true); + } - const userResponse = await getUser(); - const profileResponse = await getProfile(); + const userResponse = await getUser(); + const profileResponse = await getProfile(); - if (!userResponse.success || !profileResponse.success) { - setUser(null); - setProfile(null); - setAvatarUrl(null); - return; - } + if (!userResponse.success || !profileResponse.success) { + setUser(null); + setProfile(null); + setAvatarUrl(null); + return; + } - setUser(userResponse.data); - setProfile(profileResponse.data); + setUser(userResponse.data); + setProfile(profileResponse.data); - // Get avatar URL if available - if (profileResponse.data.avatar_url) { - const avatarResponse = await getSignedUrl({ - bucket: 'avatars', - url: profileResponse.data.avatar_url, - }); - if (avatarResponse.success) { - setAvatarUrl(avatarResponse.data); + // Get avatar URL if available + if (profileResponse.data.avatar_url) { + const avatarResponse = await getSignedUrl({ + bucket: 'avatars', + url: profileResponse.data.avatar_url, + }); + if (avatarResponse.success) { + setAvatarUrl(avatarResponse.data); + } else { + setAvatarUrl(null); + } } else { setAvatarUrl(null); } - } else { - setAvatarUrl(null); + } catch (error) { + console.error( + 'Auth fetch error: ', + error instanceof Error + ? `${error.message}` + : 'Failed to load user data!', + ); + if (!isInitialized) { + toast.error('Failed to load user data!'); + } + } finally { + if (showLoading) { + setIsLoading(false); + } + setIsInitialized(true); + fetchingRef.current = false; } - } catch (error) { - console.error( - 'Auth fetch error: ', - error instanceof Error ? - `${error.message}` : - 'Failed to load user data!' - ); - if (!isInitialized) { - toast.error('Failed to load user data!'); - } - } finally { - if (showLoading) { - setIsLoading(false); - } - setIsInitialized(true); - fetchingRef.current = false; - } - }, [isInitialized]); + }, + [isInitialized], + ); useEffect(() => { const supabase = createClient(); - + // Initial fetch with loading fetchUserData(true).catch((error) => { console.error('💥 Initial fetch error:', error); @@ -113,7 +112,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => { data: { subscription }, } = supabase.auth.onAuthStateChange(async (event, session) => { console.log('Auth state change:', event); // Debug log - + if (event === 'SIGNED_IN') { // Background refresh without loading state await fetchUserData(false); @@ -133,37 +132,42 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => { }; }, [fetchUserData]); - const updateProfile = useCallback(async (data: { - full_name?: string; - email?: string; - avatar_url?: string; - }) => { - try { - const result = await updateProfileAction(data); - if (!result.success) { - throw new Error(result.error ?? 'Failed to update profile'); - } - setProfile(result.data); - - // If avatar was updated, refresh the avatar URL - if (data.avatar_url && result.data.avatar_url) { - const avatarResponse = await getSignedUrl({ - bucket: 'avatars', - url: result.data.avatar_url, - transform: { width: 128, height: 128 }, - }); - if (avatarResponse.success) { - setAvatarUrl(avatarResponse.data); + const updateProfile = useCallback( + async (data: { + full_name?: string; + email?: string; + avatar_url?: string; + }) => { + try { + const result = await updateProfileAction(data); + if (!result.success) { + throw new Error(result.error ?? 'Failed to update profile'); } + setProfile(result.data); + + // If avatar was updated, refresh the avatar URL + if (data.avatar_url && result.data.avatar_url) { + const avatarResponse = await getSignedUrl({ + bucket: 'avatars', + url: result.data.avatar_url, + transform: { width: 128, height: 128 }, + }); + if (avatarResponse.success) { + setAvatarUrl(avatarResponse.data); + } + } + toast.success('Profile updated successfully!'); + return { success: true, data: result.data }; + } catch (error) { + console.error('Error updating profile:', error); + toast.error( + error instanceof Error ? error.message : 'Failed to update profile', + ); + return { success: false, error }; } - toast.success('Profile updated successfully!'); - return { success: true, data: result.data }; - } catch (error) { - console.error('Error updating profile:', error); - toast.error(error instanceof Error ? error.message : 'Failed to update profile'); - return { success: false, error }; - } - }, []); + }, + [], + ); const refreshUserData = useCallback(async () => { await fetchUserData(true); // Manual refresh shows loading @@ -179,11 +183,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => { refreshUserData, }; - return ( - - {children} - - ); + return {children}; }; export const useAuth = () => { diff --git a/src/components/default/StatusMessage.tsx b/src/components/default/StatusMessage.tsx index 96e72ec..9dde835 100644 --- a/src/components/default/StatusMessage.tsx +++ b/src/components/default/StatusMessage.tsx @@ -15,9 +15,7 @@ export const StatusMessage = ({ message }: { message: Message }) => { )} {'error' in message && ( -
- {message.error} -
+
{message.error}
)} {'message' in message && (
{message.message}
diff --git a/src/components/default/auth/SignInWithApple.tsx b/src/components/default/auth/SignInWithApple.tsx index 3bd0989..752beeb 100644 --- a/src/components/default/auth/SignInWithApple.tsx +++ b/src/components/default/auth/SignInWithApple.tsx @@ -17,9 +17,9 @@ export const SignInWithApple = () => { try { setStatusMessage(''); setIsSigningIn(true); - + const result = await signInWithApple(); - + if (result?.success && result.data) { // Redirect to Apple OAuth page window.location.href = result.data; @@ -28,7 +28,7 @@ export const SignInWithApple = () => { } } catch (error) { setStatusMessage( - `Error: ${error instanceof Error ? error.message : 'Could not sign in!'}` + `Error: ${error instanceof Error ? error.message : 'Could not sign in!'}`, ); } finally { setIsSigningIn(false); @@ -38,28 +38,25 @@ export const SignInWithApple = () => { }; return ( - +
- Apple logo

Sign in with Apple

- {statusMessage && ( - - )} + {statusMessage && } ); }; diff --git a/src/components/default/auth/SignInWithMicrosoft.tsx b/src/components/default/auth/SignInWithMicrosoft.tsx index da6b257..3446b49 100644 --- a/src/components/default/auth/SignInWithMicrosoft.tsx +++ b/src/components/default/auth/SignInWithMicrosoft.tsx @@ -15,9 +15,9 @@ export const SignInWithMicrosoft = () => { try { setStatusMessage(''); setIsSigningIn(true); - + const result = await signInWithMicrosoft(); - + if (result?.success && result.data) { // Redirect to Microsoft OAuth page window.location.href = result.data; @@ -26,30 +26,30 @@ export const SignInWithMicrosoft = () => { } } catch (error) { setStatusMessage( - `Error: ${error instanceof Error ? error.message : 'Could not sign in!'}` + `Error: ${error instanceof Error ? error.message : 'Could not sign in!'}`, ); } }; return ( -
+
- Microsoft logo + Microsoft logo

Sign in with Microsoft

- {statusMessage && ( - - )} + {statusMessage && } ); }; diff --git a/src/components/default/index.tsx b/src/components/default/index.tsx index ecfdfcc..21b32b1 100644 --- a/src/components/default/index.tsx +++ b/src/components/default/index.tsx @@ -1,2 +1,5 @@ -export { StatusMessage, type Message } from '@/components/default/StatusMessage'; +export { + StatusMessage, + type Message, +} from '@/components/default/StatusMessage'; export { SubmitButton } from '@/components/default/SubmitButton'; diff --git a/src/components/default/navigation/auth/AvatarDropdown.tsx b/src/components/default/navigation/auth/AvatarDropdown.tsx index abf4d90..4ea8ccb 100644 --- a/src/components/default/navigation/auth/AvatarDropdown.tsx +++ b/src/components/default/navigation/auth/AvatarDropdown.tsx @@ -31,7 +31,8 @@ const AvatarDropdown = () => { const getInitials = (name: string | null | undefined): string => { if (!name) return ''; - return name.split(' ') + return name + .split(' ') .map((n) => n[0]) .join('') .toUpperCase(); @@ -42,12 +43,19 @@ const AvatarDropdown = () => { {avatarUrl ? ( - + ) : ( - {profile?.full_name - ? getInitials(profile.full_name) - : } + {profile?.full_name ? ( + getInitials(profile.full_name) + ) : ( + + )} )} @@ -56,13 +64,19 @@ const AvatarDropdown = () => { {profile?.full_name} - + Edit profile - diff --git a/src/components/default/profile/AvatarUpload.tsx b/src/components/default/profile/AvatarUpload.tsx index 4be301d..0063f88 100644 --- a/src/components/default/profile/AvatarUpload.tsx +++ b/src/components/default/profile/AvatarUpload.tsx @@ -1,6 +1,11 @@ import { useFileUpload } from '@/lib/hooks/useFileUpload'; import { useAuth } from '@/components/context/auth'; -import { Avatar, AvatarFallback, AvatarImage, CardContent } from '@/components/ui'; +import { + Avatar, + AvatarFallback, + AvatarImage, + CardContent, +} from '@/components/ui'; import { Loader2, Pencil, Upload, User } from 'lucide-react'; type AvatarUploadProps = { @@ -28,16 +33,17 @@ export const AvatarUpload = ({ onAvatarUploaded }: AvatarUploadProps) => { maxHeight: 500, quality: 0.8, }, - replace: {replace: true, path: profile?.avatar_url ?? file.name}, + replace: { replace: true, path: profile?.avatar_url ?? file.name }, }); - if (result.success && result.path) { - await onAvatarUploaded(result.path); + if (result.success && result.data) { + await onAvatarUploaded(result.data); } }; const getInitials = (name: string | null | undefined): string => { if (!name) return ''; - return name.split(' ') + return name + .split(' ') .map((n) => n[0]) .join('') .toUpperCase(); @@ -45,23 +51,29 @@ export const AvatarUpload = ({ onAvatarUploaded }: AvatarUploadProps) => { return ( - -
-
- - {avatarUrl ? ( - - ) : ( - - {profile?.full_name - ? getInitials(profile.full_name) - : } - - )} - +
+
+ + {avatarUrl ? ( + + ) : ( + + {profile?.full_name ? ( + getInitials(profile.full_name) + ) : ( + + )} + + )} +
{ onChange={handleFileChange} disabled={isUploading} /> - {isUploading && ( -
- - Uploading... -
- )} -
+ {isUploading && ( +
+ + Uploading... +
+ )} +
); }; diff --git a/src/components/default/profile/ProfileForm.tsx b/src/components/default/profile/ProfileForm.tsx index aaa7de3..95be91a 100644 --- a/src/components/default/profile/ProfileForm.tsx +++ b/src/components/default/profile/ProfileForm.tsx @@ -27,7 +27,7 @@ type ProfileFormProps = { onSubmit: (values: z.infer) => Promise; }; -export const ProfileForm = ({onSubmit}: ProfileFormProps) => { +export const ProfileForm = ({ onSubmit }: ProfileFormProps) => { const { profile, isLoading } = useAuth(); const form = useForm>({ @@ -89,10 +89,7 @@ export const ProfileForm = ({onSubmit}: ProfileFormProps) => { />
- + Save Changes
@@ -100,4 +97,4 @@ export const ProfileForm = ({onSubmit}: ProfileFormProps) => { ); -} +}; diff --git a/src/components/default/profile/ResetPasswordForm.tsx b/src/components/default/profile/ResetPasswordForm.tsx index 340fb6d..f685ebd 100644 --- a/src/components/default/profile/ResetPasswordForm.tsx +++ b/src/components/default/profile/ResetPasswordForm.tsx @@ -69,7 +69,7 @@ export const ResetPasswordForm = ({ } } catch (error) { setStatusMessage( - error instanceof Error ? error.message : 'Password was not updated!' + error instanceof Error ? error.message : 'Password was not updated!', ); } finally { setIsLoading(false); @@ -86,7 +86,7 @@ export const ResetPasswordForm = ({
- @@ -123,10 +123,11 @@ export const ResetPasswordForm = ({ )} /> {statusMessage && ( -
diff --git a/src/lib/actions/auth.ts b/src/lib/actions/auth.ts index ed2a0fa..69858b7 100644 --- a/src/lib/actions/auth.ts +++ b/src/lib/actions/auth.ts @@ -1,13 +1,14 @@ 'use server'; import 'server-only'; -import { encodedRedirect } from '@/utils/utils'; import { createServerClient } from '@/utils/supabase'; import { headers } from 'next/headers'; import type { User } from '@/utils/supabase'; -import type { Result } from './index'; +import type { Result } from '.'; -export const signUp = async (formData: FormData): Promise> => { +export const signUp = async ( + formData: FormData, +): Promise> => { const name = formData.get('name') as string; const email = formData.get('email') as string; const password = formData.get('password') as string; @@ -15,11 +16,7 @@ export const signUp = async (formData: FormData): Promise> const origin = (await headers()).get('origin'); if (!email || !password) { - return encodedRedirect( - 'error', - '/sign-up', - 'Email & password are required', - ); + return { success: false, error: 'Email and password are required' }; } const { error } = await supabase.auth.signUp({ @@ -34,6 +31,7 @@ export const signUp = async (formData: FormData): Promise> }, }, }); + if (error) { return { success: false, error: error.message }; } else { @@ -44,9 +42,7 @@ export const signUp = async (formData: FormData): Promise> } }; -export const signIn = async ( - formData: FormData, -): Promise> => { +export const signIn = async (formData: FormData): Promise> => { const email = formData.get('email') as string; const password = formData.get('password') as string; const supabase = await createServerClient(); @@ -68,10 +64,10 @@ export const signInWithMicrosoft = async (): Promise> => { provider: 'azure', options: { scopes: 'openid, profile email offline_access', - } + }, }); if (error) return { success: false, error: error.message }; - return { success: true, data: data.url}; + return { success: true, data: data.url }; }; export const signInWithApple = async (): Promise> => { @@ -80,13 +76,15 @@ export const signInWithApple = async (): Promise> => { provider: 'apple', options: { scopes: 'openid, profile email offline_access', - } + }, }); if (error) return { success: false, error: error.message }; - return { success: true, data: data.url}; + return { success: true, data: data.url }; }; -export const forgotPassword = async (formData: FormData): Promise> => { +export const forgotPassword = async ( + formData: FormData, +): Promise> => { const email = formData.get('email') as string; const supabase = await createServerClient(); const origin = (await headers()).get('origin'); @@ -102,15 +100,22 @@ export const forgotPassword = async (formData: FormData): Promise> => { +export const resetPassword = async ( + formData: FormData, +): Promise> => { const password = formData.get('password') as string; const confirmPassword = formData.get('confirmPassword') as string; if (!password || !confirmPassword) { - return { success: false, error: 'Password and confirm password are required!' }; + return { + success: false, + error: 'Password and confirm password are required!', + }; } const supabase = await createServerClient(); if (password !== confirmPassword) { @@ -120,7 +125,10 @@ export const resetPassword = async (formData: FormData): Promise> = password, }); if (error) { - return { success: false, error: `Password update failed: ${error.message}` }; + return { + success: false, + error: `Password update failed: ${error.message}`, + }; } return { success: true, data: null }; }; @@ -128,7 +136,7 @@ export const resetPassword = async (formData: FormData): Promise> = export const signOut = async (): Promise> => { const supabase = await createServerClient(); const { error } = await supabase.auth.signOut(); - if (error) return { success: false, error: error.message } + if (error) return { success: false, error: error.message }; return { success: true, data: null }; }; diff --git a/src/lib/actions/public.ts b/src/lib/actions/public.ts index 1449237..2fdf3fb 100644 --- a/src/lib/actions/public.ts +++ b/src/lib/actions/public.ts @@ -3,7 +3,7 @@ import 'server-only'; import { createServerClient, type Profile } from '@/utils/supabase'; import { getUser } from '@/lib/actions'; -import type { Result } from './index'; +import type { Result } from '.'; export const getProfile = async (): Promise> => { try { diff --git a/src/lib/actions/storage.ts b/src/lib/actions/storage.ts index 5f6ea02..9612ff1 100755 --- a/src/lib/actions/storage.ts +++ b/src/lib/actions/storage.ts @@ -1,7 +1,7 @@ 'use server'; import 'server-only'; import { createServerClient } from '@/utils/supabase'; -import type { Result } from './index'; +import type { Result } from '.'; export type GetStorageProps = { bucket: string; @@ -38,12 +38,12 @@ export type ReplaceStorageProps = { }; export type resizeImageProps = { - file: File, + file: File; options?: { - maxWidth?: number, - maxHeight?: number, - quality?: number, - } + maxWidth?: number; + maxHeight?: number; + quality?: number; + }; }; export const getSignedUrl = async ({ @@ -75,7 +75,7 @@ export const getSignedUrl = async ({ : 'Unknown error getting signed URL', }; } -} +}; export const getPublicUrl = async ({ bucket, @@ -85,12 +85,10 @@ export const getPublicUrl = async ({ }: GetStorageProps): Promise> => { try { const supabase = await createServerClient(); - const { data } = supabase.storage - .from(bucket) - .getPublicUrl(url, { - download, - transform, - }); + const { data } = supabase.storage.from(bucket).getPublicUrl(url, { + download, + transform, + }); if (!data?.publicUrl) throw new Error('No public URL returned'); @@ -104,7 +102,7 @@ export const getPublicUrl = async ({ : 'Unknown error getting public URL', }; } -} +}; export const uploadFile = async ({ bucket, @@ -129,7 +127,7 @@ export const uploadFile = async ({ error instanceof Error ? error.message : 'Unknown error uploading file', }; } -} +}; export const replaceFile = async ({ bucket, @@ -141,7 +139,7 @@ export const replaceFile = async ({ const supabase = await createServerClient(); const { data, error } = await supabase.storage .from(bucket) - .update(path, file, {...options, upsert: true}); + .update(path, file, { ...options, upsert: true }); if (error) throw error; if (!data?.path) throw new Error('No path returned from upload'); return { success: true, data: data.path }; @@ -176,7 +174,7 @@ export const deleteFile = async ({ error instanceof Error ? error.message : 'Unknown error deleting file', }; } -} +}; // Add a helper to list files in a bucket export const listFiles = async ({ @@ -210,53 +208,49 @@ export const listFiles = async ({ error instanceof Error ? error.message : 'Unknown error listing files', }; } -} +}; export const resizeImage = async ({ file, options = {}, }: resizeImageProps): Promise => { - const { - maxWidth = 800, - maxHeight = 800, - quality = 0.8, - } = options; - return new Promise((resolve) => { - const reader = new FileReader(); - reader.readAsDataURL(file); - reader.onload = (event) => { - const img = new Image(); - img.src = event.target?.result as string; - img.onload = () => { - let width = img.width; - let height = img.height; - if (width > height) { - if (width > maxWidth) { - height = Math.round((height * maxWidth / width)); - width = maxWidth; - } - } else if (height > maxHeight) { - width = Math.round((width * maxHeight / height)); - height = maxHeight; + const { maxWidth = 800, maxHeight = 800, quality = 0.8 } = options; + return new Promise((resolve) => { + const reader = new FileReader(); + reader.readAsDataURL(file); + reader.onload = (event) => { + const img = new Image(); + img.src = event.target?.result as string; + img.onload = () => { + let width = img.width; + let height = img.height; + if (width > height) { + if (width > maxWidth) { + height = Math.round((height * maxWidth) / width); + width = maxWidth; } - const canvas = document.createElement('canvas'); - canvas.width = width; - canvas.height = height; - const ctx = canvas.getContext('2d'); - ctx?.drawImage(img, 0, 0, width, height); - canvas.toBlob( - (blob) => { - if (!blob) return; - const resizedFile = new File([blob], file.name, { - type: 'imgage/jpeg', - lastModified: Date.now(), - }); - resolve(resizedFile); - }, - 'image/jpeg', - quality - ); - }; + } else if (height > maxHeight) { + width = Math.round((width * maxHeight) / height); + height = maxHeight; + } + const canvas = document.createElement('canvas'); + canvas.width = width; + canvas.height = height; + const ctx = canvas.getContext('2d'); + ctx?.drawImage(img, 0, 0, width, height); + canvas.toBlob( + (blob) => { + if (!blob) return; + const resizedFile = new File([blob], file.name, { + type: 'imgage/jpeg', + lastModified: Date.now(), + }); + resolve(resizedFile); + }, + 'image/jpeg', + quality, + ); }; - }); + }; + }); }; diff --git a/src/lib/hooks/auth.ts b/src/lib/hooks/auth.ts index 5826515..e4e5ff3 100644 --- a/src/lib/hooks/auth.ts +++ b/src/lib/hooks/auth.ts @@ -1,11 +1,11 @@ -'use client' -import { encodedRedirect } from '@/utils/utils'; +'use client'; import { createClient } from '@/utils/supabase'; import type { User } from '@/utils/supabase'; -import type { Result } from './index'; +import type { Result } from '.'; - -export const signUp = async (formData: FormData): Promise> => { +export const signUp = async ( + formData: FormData, +): Promise> => { const name = formData.get('name') as string; const email = formData.get('email') as string; const password = formData.get('password') as string; @@ -13,11 +13,7 @@ export const signUp = async (formData: FormData): Promise> const origin = process.env.NEXT_PUBLIC_SITE_URL!; if (!email || !password) { - return encodedRedirect( - 'error', - '/sign-up', - 'Email & password are required', - ); + return { success: false, error: 'Email and password are required' }; } const { error } = await supabase.auth.signUp({ @@ -42,9 +38,7 @@ export const signUp = async (formData: FormData): Promise> } }; -export const signIn = async ( - formData: FormData, -): Promise> => { +export const signIn = async (formData: FormData): Promise> => { const email = formData.get('email') as string; const password = formData.get('password') as string; const supabase = createClient(); @@ -60,17 +54,16 @@ export const signIn = async ( } }; - export const signInWithMicrosoft = async (): Promise> => { const supabase = createClient(); const { data, error } = await supabase.auth.signInWithOAuth({ provider: 'azure', options: { scopes: 'openid, profile email offline_access', - } + }, }); if (error) return { success: false, error: error.message }; - return { success: true, data: data.url}; + return { success: true, data: data.url }; }; export const signInWithApple = async (): Promise> => { @@ -79,13 +72,15 @@ export const signInWithApple = async (): Promise> => { provider: 'apple', options: { scopes: 'openid, profile email offline_access', - } + }, }); if (error) return { success: false, error: error.message }; - return { success: true, data: data.url}; + return { success: true, data: data.url }; }; -export const forgotPassword = async (formData: FormData): Promise> => { +export const forgotPassword = async ( + formData: FormData, +): Promise> => { const email = formData.get('email') as string; const supabase = createClient(); const origin = process.env.NEXT_PUBLIC_SITE_URL!; @@ -101,15 +96,22 @@ export const forgotPassword = async (formData: FormData): Promise> => { +export const resetPassword = async ( + formData: FormData, +): Promise> => { const password = formData.get('password') as string; const confirmPassword = formData.get('confirmPassword') as string; if (!password || !confirmPassword) { - return { success: false, error: 'Password and confirm password are required!' }; + return { + success: false, + error: 'Password and confirm password are required!', + }; } const supabase = createClient(); if (password !== confirmPassword) { @@ -119,7 +121,10 @@ export const resetPassword = async (formData: FormData): Promise> = password, }); if (error) { - return { success: false, error: `Password update failed: ${error.message}` }; + return { + success: false, + error: `Password update failed: ${error.message}`, + }; } return { success: true, data: null }; }; @@ -127,7 +132,7 @@ export const resetPassword = async (formData: FormData): Promise> = export const signOut = async (): Promise> => { const supabase = createClient(); const { error } = await supabase.auth.signOut(); - if (error) return { success: false, error: error.message } + if (error) return { success: false, error: error.message }; return { success: true, data: null }; }; diff --git a/src/lib/hooks/public.ts b/src/lib/hooks/public.ts index 87786b8..7329d33 100644 --- a/src/lib/hooks/public.ts +++ b/src/lib/hooks/public.ts @@ -2,7 +2,7 @@ import { createClient, type Profile } from '@/utils/supabase'; import { getUser } from '@/lib/hooks'; -import type { Result } from './index'; +import type { Result } from '.'; export const getProfile = async (): Promise> => { try { diff --git a/src/lib/hooks/storage.ts b/src/lib/hooks/storage.ts index 6ac9c77..8b11c9d 100644 --- a/src/lib/hooks/storage.ts +++ b/src/lib/hooks/storage.ts @@ -1,7 +1,7 @@ 'use client'; import { createClient } from '@/utils/supabase'; -import type { Result } from './index'; +import type { Result } from '.'; export type GetStorageProps = { bucket: string; @@ -38,12 +38,12 @@ export type ReplaceStorageProps = { }; export type resizeImageProps = { - file: File, + file: File; options?: { - maxWidth?: number, - maxHeight?: number, - quality?: number, - } + maxWidth?: number; + maxHeight?: number; + quality?: number; + }; }; export const getSignedUrl = async ({ @@ -75,7 +75,7 @@ export const getSignedUrl = async ({ : 'Unknown error getting signed URL', }; } -} +}; export const getPublicUrl = async ({ bucket, @@ -85,12 +85,10 @@ export const getPublicUrl = async ({ }: GetStorageProps): Promise> => { try { const supabase = createClient(); - const { data } = supabase.storage - .from(bucket) - .getPublicUrl(url, { - download, - transform, - }); + const { data } = supabase.storage.from(bucket).getPublicUrl(url, { + download, + transform, + }); if (!data?.publicUrl) throw new Error('No public URL returned'); @@ -104,7 +102,7 @@ export const getPublicUrl = async ({ : 'Unknown error getting public URL', }; } -} +}; export const uploadFile = async ({ bucket, @@ -129,7 +127,7 @@ export const uploadFile = async ({ error instanceof Error ? error.message : 'Unknown error uploading file', }; } -} +}; export const replaceFile = async ({ bucket, @@ -179,7 +177,7 @@ export const deleteFile = async ({ error instanceof Error ? error.message : 'Unknown error deleting file', }; } -} +}; // Add a helper to list files in a bucket export const listFiles = async ({ @@ -213,53 +211,49 @@ export const listFiles = async ({ error instanceof Error ? error.message : 'Unknown error listing files', }; } -} +}; export const resizeImage = async ({ file, options = {}, }: resizeImageProps): Promise => { - const { - maxWidth = 800, - maxHeight = 800, - quality = 0.8, - } = options; - return new Promise((resolve) => { - const reader = new FileReader(); - reader.readAsDataURL(file); - reader.onload = (event) => { - const img = new Image(); - img.src = event.target?.result as string; - img.onload = () => { - let width = img.width; - let height = img.height; - if (width > height) { - if (width > maxWidth) { - height = Math.round((height * maxWidth / width)); - width = maxWidth; - } - } else if (height > maxHeight) { - width = Math.round((width * maxHeight / height)); - height = maxHeight; + const { maxWidth = 800, maxHeight = 800, quality = 0.8 } = options; + return new Promise((resolve) => { + const reader = new FileReader(); + reader.readAsDataURL(file); + reader.onload = (event) => { + const img = new Image(); + img.src = event.target?.result as string; + img.onload = () => { + let width = img.width; + let height = img.height; + if (width > height) { + if (width > maxWidth) { + height = Math.round((height * maxWidth) / width); + width = maxWidth; } - const canvas = document.createElement('canvas'); - canvas.width = width; - canvas.height = height; - const ctx = canvas.getContext('2d'); - ctx?.drawImage(img, 0, 0, width, height); - canvas.toBlob( - (blob) => { - if (!blob) return; - const resizedFile = new File([blob], file.name, { - type: 'imgage/jpeg', - lastModified: Date.now(), - }); - resolve(resizedFile); - }, - 'image/jpeg', - quality - ); - }; + } else if (height > maxHeight) { + width = Math.round((width * maxHeight) / height); + height = maxHeight; + } + const canvas = document.createElement('canvas'); + canvas.width = width; + canvas.height = height; + const ctx = canvas.getContext('2d'); + ctx?.drawImage(img, 0, 0, width, height); + canvas.toBlob( + (blob) => { + if (!blob) return; + const resizedFile = new File([blob], file.name, { + type: 'imgage/jpeg', + lastModified: Date.now(), + }); + resolve(resizedFile); + }, + 'image/jpeg', + quality, + ); }; - }); + }; + }); }; diff --git a/src/lib/hooks/useFileUpload.ts b/src/lib/hooks/useFileUpload.ts index aee695b..bfcd0c2 100644 --- a/src/lib/hooks/useFileUpload.ts +++ b/src/lib/hooks/useFileUpload.ts @@ -1,14 +1,13 @@ -'use client' +'use client'; import { useState, useRef } from 'react'; import { replaceFile, uploadFile } from '@/lib/hooks'; import { toast } from 'sonner'; import { useAuth } from '@/components/context/auth'; import { resizeImage } from '@/lib/hooks'; +import type { Result } from '.'; -export type Replace = - | { replace: true, path: string } - | false; +export type Replace = { replace: true; path: string } | false; export type uploadToStorageProps = { file: File; @@ -33,7 +32,7 @@ export const useFileUpload = () => { resize = false, options = {}, replace = false, - }: uploadToStorageProps) => { + }: uploadToStorageProps): Promise> => { try { if (!isAuthenticated) throw new Error('User is not authenticated'); @@ -48,10 +47,9 @@ export const useFileUpload = () => { }, }); if (!updateResult.success) { - console.error('Error updating file:', updateResult.error); + return { success: false, error: updateResult.error }; } else { - console.log('We used the new update function hopefully it worked!'); - return { success: true, path: updateResult.data }; + return { success: true, data: updateResult.data }; } } @@ -77,15 +75,21 @@ export const useFileUpload = () => { throw new Error(uploadResult.error || `Failed to upload to ${bucket}`); } - return { success: true, path: uploadResult.data }; + return { success: true, data: uploadResult.data }; } catch (error) { - console.error(`Error uploading to ${bucket}:`, error); toast.error( error instanceof Error ? error.message : `Failed to upload to ${bucket}`, ); - return { success: false, error }; + return { + success: false, + error: `Error: ${ + error instanceof Error + ? error.message + : `Failed to upload to ${bucket}` + }`, + }; } finally { setIsUploading(false); // Clear the input value so the same file can be selected again diff --git a/src/server/docker/volumes/functions/hello/index.ts b/src/server/docker/volumes/functions/hello/index.ts index f1e20b9..7ae5cc1 100644 --- a/src/server/docker/volumes/functions/hello/index.ts +++ b/src/server/docker/volumes/functions/hello/index.ts @@ -2,14 +2,13 @@ // https://deno.land/manual/getting_started/setup_your_environment // This enables autocomplete, go to definition, etc. -import { serve } from "https://deno.land/std@0.177.1/http/server.ts" +import { serve } from 'https://deno.land/std@0.177.1/http/server.ts'; serve(async () => { - return new Response( - `"Hello from Edge Functions!"`, - { headers: { "Content-Type": "application/json" } }, - ) -}) + return new Response(`"Hello from Edge Functions!"`, { + headers: { 'Content-Type': 'application/json' }, + }); +}); // To invoke: // curl 'http://localhost:/functions/v1/hello' \ diff --git a/src/server/docker/volumes/functions/main/index.ts b/src/server/docker/volumes/functions/main/index.ts index a094010..291c1e0 100644 --- a/src/server/docker/volumes/functions/main/index.ts +++ b/src/server/docker/volumes/functions/main/index.ts @@ -1,78 +1,78 @@ -import { serve } from 'https://deno.land/std@0.131.0/http/server.ts' -import * as jose from 'https://deno.land/x/jose@v4.14.4/index.ts' +import { serve } from 'https://deno.land/std@0.131.0/http/server.ts'; +import * as jose from 'https://deno.land/x/jose@v4.14.4/index.ts'; -console.log('main function started') +console.log('main function started'); -const JWT_SECRET = Deno.env.get('JWT_SECRET') -const VERIFY_JWT = Deno.env.get('VERIFY_JWT') === 'true' +const JWT_SECRET = Deno.env.get('JWT_SECRET'); +const VERIFY_JWT = Deno.env.get('VERIFY_JWT') === 'true'; function getAuthToken(req: Request) { - const authHeader = req.headers.get('authorization') + const authHeader = req.headers.get('authorization'); if (!authHeader) { - throw new Error('Missing authorization header') + throw new Error('Missing authorization header'); } - const [bearer, token] = authHeader.split(' ') + const [bearer, token] = authHeader.split(' '); if (bearer !== 'Bearer') { - throw new Error(`Auth header is not 'Bearer {token}'`) + throw new Error(`Auth header is not 'Bearer {token}'`); } - return token + return token; } async function verifyJWT(jwt: string): Promise { - const encoder = new TextEncoder() - const secretKey = encoder.encode(JWT_SECRET) + const encoder = new TextEncoder(); + const secretKey = encoder.encode(JWT_SECRET); try { - await jose.jwtVerify(jwt, secretKey) + await jose.jwtVerify(jwt, secretKey); } catch (err) { - console.error(err) - return false + console.error(err); + return false; } - return true + return true; } serve(async (req: Request) => { if (req.method !== 'OPTIONS' && VERIFY_JWT) { try { - const token = getAuthToken(req) - const isValidJWT = await verifyJWT(token) + const token = getAuthToken(req); + const isValidJWT = await verifyJWT(token); if (!isValidJWT) { return new Response(JSON.stringify({ msg: 'Invalid JWT' }), { status: 401, headers: { 'Content-Type': 'application/json' }, - }) + }); } } catch (e) { - console.error(e) + console.error(e); return new Response(JSON.stringify({ msg: e.toString() }), { status: 401, headers: { 'Content-Type': 'application/json' }, - }) + }); } } - const url = new URL(req.url) - const { pathname } = url - const path_parts = pathname.split('/') - const service_name = path_parts[1] + const url = new URL(req.url); + const { pathname } = url; + const path_parts = pathname.split('/'); + const service_name = path_parts[1]; if (!service_name || service_name === '') { - const error = { msg: 'missing function name in request' } + const error = { msg: 'missing function name in request' }; return new Response(JSON.stringify(error), { status: 400, headers: { 'Content-Type': 'application/json' }, - }) + }); } - const servicePath = `/home/deno/functions/${service_name}` - console.error(`serving the request with ${servicePath}`) + const servicePath = `/home/deno/functions/${service_name}`; + console.error(`serving the request with ${servicePath}`); - const memoryLimitMb = 150 - const workerTimeoutMs = 1 * 60 * 1000 - const noModuleCache = false - const importMapPath = null - const envVarsObj = Deno.env.toObject() - const envVars = Object.keys(envVarsObj).map((k) => [k, envVarsObj[k]]) + const memoryLimitMb = 150; + const workerTimeoutMs = 1 * 60 * 1000; + const noModuleCache = false; + const importMapPath = null; + const envVarsObj = Deno.env.toObject(); + const envVars = Object.keys(envVarsObj).map((k) => [k, envVarsObj[k]]); try { const worker = await EdgeRuntime.userWorkers.create({ @@ -82,13 +82,13 @@ serve(async (req: Request) => { noModuleCache, importMapPath, envVars, - }) - return await worker.fetch(req) + }); + return await worker.fetch(req); } catch (e) { - const error = { msg: e.toString() } + const error = { msg: e.toString() }; return new Response(JSON.stringify(error), { status: 500, headers: { 'Content-Type': 'application/json' }, - }) + }); } -}) +}); diff --git a/src/utils/supabase/middleware.ts b/src/utils/supabase/middleware.ts index c71a684..b4c2cd3 100644 --- a/src/utils/supabase/middleware.ts +++ b/src/utils/supabase/middleware.ts @@ -2,9 +2,9 @@ import { createServerClient } from '@supabase/ssr'; import { type NextRequest, NextResponse } from 'next/server'; import type { Database } from '@/utils/supabase/types'; -export const updateSession = async (request: NextRequest) => { - // This `try/catch` block is only here for the interactive tutorial. - // Feel free to remove once you have Supabase connected. +export const updateSession = async ( + request: NextRequest, +): Promise => { try { // Create an unmodified response let response = NextResponse.next({ @@ -45,15 +45,8 @@ export const updateSession = async (request: NextRequest) => { return NextResponse.redirect(new URL('/sign-in', request.url)); } - //if (request.nextUrl.pathname === '/' && !user.error) { - //return NextResponse.redirect(new URL('/protected', request.url)); - //} - return response; } catch (e) { - // If you are here, a Supabase client could not be created! - // This is likely because you have not set up environment variables. - // Check out http://localhost:3000 for Next Steps. return NextResponse.next({ request: { headers: request.headers, diff --git a/src/utils/supabase/server.ts b/src/utils/supabase/server.ts index d493c0c..82462a5 100644 --- a/src/utils/supabase/server.ts +++ b/src/utils/supabase/server.ts @@ -1,4 +1,4 @@ -'use server' +'use server'; import 'server-only'; import { createServerClient as CreateServerClient } from '@supabase/ssr'; diff --git a/src/utils/utils.ts b/src/utils/utils.ts deleted file mode 100644 index d573047..0000000 --- a/src/utils/utils.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { redirect } from 'next/navigation'; - -/** - * Redirects to a specified path with an encoded message as a query parameter. - * @param {('error' | 'success')} type - The type of message, either 'error' or 'success'. - * @param {string} path - The path to redirect to. - * @param {string} message - The message to be encoded and added as a query parameter. - * @returns {never} This function doesn't return as it triggers a redirect. - */ -export function encodedRedirect( - type: 'error' | 'success', - path: string, - message: string, -) { - return redirect(`${path}?${type}=${encodeURIComponent(message)}`); -}