|  | 
|  | 1 | +// // pages/api/auth/[...nextauth].ts | 
|  | 2 | +// import NextAuth from 'next-auth'; | 
|  | 3 | +// import GoogleProvider from 'next-auth/providers/google'; | 
|  | 4 | +// import FacebookProvider from 'next-auth/providers/facebook'; | 
|  | 5 | +// import CredentialsProvider from 'next-auth/providers/credentials'; | 
|  | 6 | +// import { DrizzleAdapter } from '@auth/drizzle-adapter'; | 
|  | 7 | +// import { db } from '../../../schema'; | 
|  | 8 | +// import { getAdapterUser, createAdapterUser, linkAccountToUser, createAccount } from '../../../utils/db'; | 
|  | 9 | + | 
|  | 10 | +// export default NextAuth({ | 
|  | 11 | +//   adapter: DrizzleAdapter(db), | 
|  | 12 | +//   providers: [ | 
|  | 13 | +//     CredentialsProvider({ | 
|  | 14 | +//       name: 'Credentials', | 
|  | 15 | +//       credentials: { | 
|  | 16 | +//         username: { label: 'Username', type: 'text' }, | 
|  | 17 | +//         password: { label: 'Password', type: 'password' } | 
|  | 18 | +//       }, | 
|  | 19 | +//       authorize: async (credentials) => { | 
|  | 20 | +//         const user = await getAdapterUser(credentials.email as string); | 
|  | 21 | +//         if (user) { | 
|  | 22 | +//           return user; | 
|  | 23 | +//         } | 
|  | 24 | + | 
|  | 25 | +//         // Create a new user and their account | 
|  | 26 | +//         const newUser = await createAdapterUser(credentials); | 
|  | 27 | +//         await createAccount(newUser.id, credentials); | 
|  | 28 | + | 
|  | 29 | +//         return newUser; | 
|  | 30 | +//       } | 
|  | 31 | +//     }), | 
|  | 32 | +//     GoogleProvider({ | 
|  | 33 | +//       clientId: process.env.GOOGLE_CLIENT_ID, | 
|  | 34 | +//       clientSecret: process.env.GOOGLE_CLIENT_SECRET, | 
|  | 35 | +//       allowDangerousEmailAccountLinking: true | 
|  | 36 | +//     }), | 
|  | 37 | +//     FacebookProvider({ | 
|  | 38 | +//       clientId: process.env.FACEBOOK_CLIENT_ID, | 
|  | 39 | +//       clientSecret: process.env.FACEBOOK_CLIENT_SECRET, | 
|  | 40 | +//       allowDangerousEmailAccountLinking: true | 
|  | 41 | +//     }), | 
|  | 42 | +//   ], | 
|  | 43 | +//   callbacks: { | 
|  | 44 | +//     async signIn({ account, profile, user }) { | 
|  | 45 | +//       if (account.provider === 'google' || account.provider === 'facebook') { | 
|  | 46 | +//         const existingUser = await getAdapterUser(profile.email as string); | 
|  | 47 | +//         if (existingUser) { | 
|  | 48 | +//           await linkAccountToUser(existingUser.id, account); | 
|  | 49 | +//         } | 
|  | 50 | +//       } | 
|  | 51 | +//       return true; | 
|  | 52 | +//     }, | 
|  | 53 | +//   }, | 
|  | 54 | +// }); | 
|  | 55 | + | 
|  | 56 | +// ----------------------------------------------------- | 
|  | 57 | + | 
|  | 58 | +// app/api/auth/unlink-account/route.ts | 
|  | 59 | +// import { NextResponse } from 'next/server'; | 
|  | 60 | +// import { unlinkAccount } from '../../../../utils/db'; | 
|  | 61 | + | 
|  | 62 | +// export async function POST(request: Request) { | 
|  | 63 | +//   const { userId, provider, providerAccountId } = await request.json(); | 
|  | 64 | + | 
|  | 65 | +//   if (!userId || !provider || !providerAccountId) { | 
|  | 66 | +//     return NextResponse.json({ error: 'Missing required fields' }, { status: 400 }); | 
|  | 67 | +//   } | 
|  | 68 | + | 
|  | 69 | +//   try { | 
|  | 70 | +//     await unlinkAccount(userId, provider, providerAccountId); | 
|  | 71 | +//     return NextResponse.json({ message: 'Account unlinked successfully' }, { status: 200 }); | 
|  | 72 | +//   } catch (error) { | 
|  | 73 | +//     return NextResponse.json({ error: 'Error unlinking account' }, { status: 500 }); | 
|  | 74 | +//   } | 
|  | 75 | +// } | 
|  | 76 | + | 
|  | 77 | +// ----------------------------------------------------- | 
|  | 78 | + | 
|  | 79 | +// app/api/auth/link-account/route.ts | 
|  | 80 | +// import { NextResponse } from 'next/server'; | 
|  | 81 | +// import { linkAccount } from '../../../../utils/db'; | 
|  | 82 | +// import type { AdapterAccount } from '@auth/core/adapters'; | 
|  | 83 | + | 
|  | 84 | +// export async function POST(request: Request) { | 
|  | 85 | +//   const { userId, accountData } = await request.json(); | 
|  | 86 | + | 
|  | 87 | +//   if (!userId || !accountData) { | 
|  | 88 | +//     return NextResponse.json({ error: 'Missing required fields' }, { status: 400 }); | 
|  | 89 | +//   } | 
|  | 90 | + | 
|  | 91 | +//   try { | 
|  | 92 | +//     await linkAccount(userId, accountData as AdapterAccount); | 
|  | 93 | +//     return NextResponse.json({ message: 'Account linked successfully' }, { status: 200 }); | 
|  | 94 | +//   } catch (error) { | 
|  | 95 | +//     return NextResponse.json({ error: 'Error linking account' }, { status: 500 }); | 
|  | 96 | +//   } | 
|  | 97 | +// } | 
|  | 98 | + | 
|  | 99 | +// ----------------------------------------------------- | 
|  | 100 | + | 
|  | 101 | +// app/api/auth/delete-user/route.ts | 
|  | 102 | +// import { NextResponse } from 'next/server'; | 
|  | 103 | +// import { deleteUser } from '../../../../utils/db'; | 
|  | 104 | + | 
|  | 105 | +// export async function POST(request: Request) { | 
|  | 106 | +//   const { userId } = await request.json(); | 
|  | 107 | + | 
|  | 108 | +//   if (!userId) { | 
|  | 109 | +//     return NextResponse.json({ error: 'Missing required fields' }, { status: 400 }); | 
|  | 110 | +//   } | 
|  | 111 | + | 
|  | 112 | +//   try { | 
|  | 113 | +//     await deleteUser(userId); | 
|  | 114 | +//     return NextResponse.json({ message: 'User deleted successfully' }, { status: 200 }); | 
|  | 115 | +//   } catch (error) { | 
|  | 116 | +//     return NextResponse.json({ error: 'Error deleting user' }, { status: 500 }); | 
|  | 117 | +//   } | 
|  | 118 | +// } | 
0 commit comments