solve mail backend 5
This commit is contained in:
parent
2c3a4ffca6
commit
eba4df1e4d
@ -96,11 +96,26 @@ export const authOptions: NextAuthOptions = {
|
||||
},
|
||||
callbacks: {
|
||||
async signIn({ user, account, profile }) {
|
||||
if (!user.email) return false;
|
||||
if (!user.email) {
|
||||
console.error('No email provided in user profile');
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
console.log('Attempting to create/update user:', {
|
||||
id: user.id,
|
||||
email: user.email
|
||||
});
|
||||
|
||||
// First check if user exists
|
||||
const existingUser = await prisma.user.findUnique({
|
||||
where: { id: user.id }
|
||||
});
|
||||
|
||||
console.log('Existing user check:', existingUser);
|
||||
|
||||
// Create or update user in local database
|
||||
await prisma.user.upsert({
|
||||
const result = await prisma.user.upsert({
|
||||
where: { id: user.id },
|
||||
update: {
|
||||
email: user.email,
|
||||
@ -112,9 +127,11 @@ export const authOptions: NextAuthOptions = {
|
||||
password: '', // We don't store password for Keycloak users
|
||||
},
|
||||
});
|
||||
|
||||
console.log('User upsert result:', result);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Error creating/updating user:', error);
|
||||
console.error('Error in signIn callback:', error);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
@ -7,7 +7,10 @@ import { prisma } from '@/lib/prisma';
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const session = await getServerSession(authOptions);
|
||||
console.log('Session in mail login:', session);
|
||||
|
||||
if (!session?.user?.id) {
|
||||
console.error('No user ID in session');
|
||||
return NextResponse.json(
|
||||
{ error: 'Unauthorized' },
|
||||
{ status: 401 }
|
||||
@ -15,11 +18,15 @@ export async function POST(request: Request) {
|
||||
}
|
||||
|
||||
// Verify user exists
|
||||
console.log('Checking for user with ID:', session.user.id);
|
||||
const user = await prisma.user.findUnique({
|
||||
where: { id: session.user.id }
|
||||
});
|
||||
|
||||
console.log('User found in database:', user);
|
||||
|
||||
if (!user) {
|
||||
console.error('User not found in database');
|
||||
return NextResponse.json(
|
||||
{ error: 'User not found' },
|
||||
{ status: 404 }
|
||||
|
||||
Loading…
Reference in New Issue
Block a user