fix(auth): port dev auto-login to Next.js 16 proxy.ts
Deploy to route.crispygoat.com / deploy (push) Successful in 3m8s
Deploy to route.crispygoat.com / deploy (push) Successful in 3m8s
Next.js 16 renamed middleware.ts to proxy.ts and only allows one of the two. Delete src/middleware.ts and rewrite src/proxy.ts to do the dev auto-login + /login bounce + /admin gate explicitly (no NextAuth auth() wrapper — auth.handler() returns a NextMiddleware taking (req, event), which makes wrapping it awkward when we also need to set cookies on the response). Drop the now-dead 'authorized' callback from auth.config.ts (it was only fired by the NextAuth wrapper, which we no longer use). Migration 209: add a defensive unique constraint on admin_users.user_id so the ON CONFLICT (user_id) clause in the new RPC resolves regardless of whether the Supabase-dashboard-created table shipped with one.
This commit is contained in:
@@ -11,6 +11,35 @@
|
||||
ALTER TABLE admin_users
|
||||
ADD COLUMN IF NOT EXISTS can_manage_settings BOOLEAN NOT NULL DEFAULT false;
|
||||
|
||||
-- Defensive: ensure admin_users.user_id has a unique constraint so the
|
||||
-- `ON CONFLICT (user_id)` below resolves. The table was created via the
|
||||
-- Supabase dashboard — we can't be sure the dashboard created a UNIQUE
|
||||
-- index on user_id. If the constraint is missing, the ON CONFLICT
|
||||
-- clause will fail the whole "Apply migrations" step on the deploy
|
||||
-- runner. Skip silently if a matching unique/primary constraint already
|
||||
-- exists, otherwise add one (cleaning up any duplicate rows first so
|
||||
-- the ADD CONSTRAINT doesn't fail).
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM pg_constraint
|
||||
WHERE conrelid = 'public.admin_users'::regclass
|
||||
AND contype IN ('u', 'p') -- unique or primary key
|
||||
AND pg_get_constraintdef(oid) ILIKE '%(user_id)%'
|
||||
) THEN
|
||||
-- Shouldn't happen in practice (this RPC is the only writer for new
|
||||
-- rows), but guard against duplicate user_id values that would
|
||||
-- block the unique constraint from being created.
|
||||
DELETE FROM admin_users a
|
||||
USING admin_users b
|
||||
WHERE a.user_id = b.user_id
|
||||
AND a.ctid > b.ctid;
|
||||
ALTER TABLE admin_users
|
||||
ADD CONSTRAINT admin_users_user_id_key UNIQUE (user_id);
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- SECURITY DEFINER RPC: upsert a platform_admin row for the given
|
||||
-- Auth.js user id.
|
||||
--
|
||||
|
||||
Reference in New Issue
Block a user