From d8ead667d0c44846dafe49432ea9db28edc419d9 Mon Sep 17 00:00:00 2001 From: Mark Henderson Date: Fri, 27 Feb 2026 12:39:25 -0800 Subject: [PATCH] fix: create fs_user on sign-in, fix projects fetch Made-with: Cursor --- lib/auth/authOptions.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/auth/authOptions.ts b/lib/auth/authOptions.ts index 60227c1..07c62d4 100644 --- a/lib/auth/authOptions.ts +++ b/lib/auth/authOptions.ts @@ -2,6 +2,7 @@ import { NextAuthOptions } from "next-auth"; import GoogleProvider from "next-auth/providers/google"; import { PrismaAdapter } from "@next-auth/prisma-adapter"; import { PrismaClient } from "@prisma/client"; +import { query } from "@/lib/db-postgres"; const prisma = new PrismaClient(); @@ -24,6 +25,23 @@ export const authOptions: NextAuthOptions = { } return session; }, + async signIn({ user }) { + if (!user?.email) return true; + try { + const workspace = user.email.split("@")[0].toLowerCase().replace(/[^a-z0-9]+/g, "-") + "-account"; + await query(` + INSERT INTO fs_users (id, user_id, data) + VALUES (gen_random_uuid()::text, $1, $2::jsonb) + ON CONFLICT ((data->>'email')) DO UPDATE + SET user_id = EXCLUDED.user_id, + data = fs_users.data || EXCLUDED.data, + updated_at = NOW() + `, [user.id, JSON.stringify({ email: user.email, name: user.name, image: user.image, workspace })]); + } catch (e) { + console.error("[signIn] Failed to upsert fs_user:", e); + } + return true; + }, }, session: { strategy: "database",