diff --git a/package.json b/package.json index c442b01..7e96afd 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "@astrojs/check": "^0.9.10", "@astrojs/tailwind": "^6.0.2", "@astrojs/ts-plugin": "^1.10.12", + "@supabase/ssr": "^0.12.7", "@supabase/supabase-js": "^2.116.0", "astro": "^7.3.3", "tailwindcss": "^3.4.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c2a7809..0d195b5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -27,6 +27,9 @@ dependencies: '@astrojs/ts-plugin': specifier: ^1.10.12 version: 1.10.12 + '@supabase/ssr': + specifier: ^0.12.7 + version: 0.12.7(@supabase/supabase-js@2.116.0) '@supabase/supabase-js': specifier: ^2.116.0 version: 2.116.0 @@ -1259,6 +1262,15 @@ packages: tslib: 2.8.1 dev: false + /@supabase/ssr@0.12.7(@supabase/supabase-js@2.116.0): + resolution: {integrity: sha512-wiBtEie1KkRJi9RrZWY3R2imRhX1JY7qMyUCH2z9AUk15gQebNEplM+urbCKamdxaTJLXUU6LlpkJsaxhojCEg==} + peerDependencies: + '@supabase/supabase-js': ^2.114.0 + dependencies: + '@supabase/supabase-js': 2.116.0 + cookie: 1.1.1 + dev: false + /@supabase/storage-js@2.116.0: resolution: {integrity: sha512-6/3hR6vccBP6oGM5B6RfbwZcTCKmQOodd/ZWQdsw8yJsU5zO/a//oBL6yLnmgxcjnHSrelW8rsO7hL5DPybyUQ==} engines: {node: '>=22.0.0'} @@ -1760,6 +1772,11 @@ packages: resolution: {integrity: sha512-lXVyvUvrNXblMqzIRrxHb57UUVmqsSWlxqt3XIjCkUP0wDAf6uicO6KMbEgYrMNtEvWgWHwe42CKxPu9MYAnWw==} dev: false + /cookie@1.1.1: + resolution: {integrity: sha512-ei8Aos7ja0weRpFzJnEA9UHJ/7XQmqglbRwnf2ATjcB9Wq874VKH9kfjjirM6UhU2/E5fFYadylyhFldcqSidQ==} + engines: {node: '>=18'} + dev: false + /cookie@2.0.1: resolution: {integrity: sha512-yuToqVvRrj6pfDXREyQAAv8SkAEk/8GS3jQRTiUMm66TVtBYmqQeoEjL2Lmq8Rpo6271vH76InTChTitEAm65w==} engines: {node: '>=22'} diff --git a/src/lib/supabase.ts b/src/lib/supabase.ts index 8bd64d2..8713cbf 100644 --- a/src/lib/supabase.ts +++ b/src/lib/supabase.ts @@ -1,9 +1,19 @@ -import {createClient} from '@supabase/supabase-js'; +import {createBrowserClient} from '@supabase/ssr'; // Same Supabase project the iOS app uses (~/code/insider-trading-app). The // publishable key is safe to embed client-side — RLS, not key secrecy, // protects data (insider-trading-app DESIGN.md §3.4b). -export const supabase = createClient( +// +// createBrowserClient (not plain createClient) stores the session -- and, +// critically, the PKCE code_verifier used mid-OAuth-redirect -- in a cookie +// instead of localStorage. Safari's Intelligent Tracking Prevention can evict +// localStorage written just before a redirect through a shared domain like +// supabase.co, which silently broke Google sign-in on Safari (the code +// exchange had nothing to read the verifier back from). Cookies set during a +// top-level navigation aren't subject to that restriction. No backend +// required -- this works in a plain client-rendered page, not just SSR +// frameworks. +export const supabase = createBrowserClient( import.meta.env.PUBLIC_SUPABASE_URL, import.meta.env.PUBLIC_SUPABASE_PUBLISHABLE_KEY );