import { User } from "../../types"; import { SignInOptions } from "../AuthProvider"; // NextAuth session type (simplified) interface NextAuthSession { user?: { id?: string; email?: string; name?: string; image?: string; }; } // Helper function to convert NextAuth user to our User type const convertNextAuthUser = ( nextAuthUser: NextAuthSession["user"] ): User | null => { if (!nextAuthUser) return null; return { id: nextAuthUser.id || "", email: nextAuthUser.email || "", name: nextAuthUser.name || "", avatar_url: nextAuthUser.image, role: "customer", // Default role, can be customized created_at: new Date().toISOString(), updated_at: new Date().toISOString(), }; }; // NextAuth adapter for AuthProvider export const createNextAuthAdapter = (nextAuth?: { getSession: () => Promise; signIn: (provider?: string, options?: SignInOptions) => Promise; signOut: () => Promise; }) => { if (!nextAuth) { console.warn("NextAuth not provided to adapter"); return {}; } return { getSession: async () => { const session = await nextAuth.getSession(); return { user: convertNextAuthUser(session?.user), }; }, signInAdapter: async (provider?: string, options?: SignInOptions) => { await nextAuth.signIn(provider, options); }, signOutAdapter: async () => { await nextAuth.signOut(); }, }; };