fix: use maybeSingle for settings query to avoid failing when the table is empty
All checks were successful
Staging Build / build (push) Successful in 2m18s
All checks were successful
Staging Build / build (push) Successful in 2m18s
This commit is contained in:
@@ -39,11 +39,13 @@ export async function GET() {
|
||||
return NextResponse.json({ error: 'Insufficient permissions' }, { status: 403 });
|
||||
}
|
||||
|
||||
const { data, error } = await supabase.from('settings').select('*').single();
|
||||
const { data, error } = await supabase.from('settings').select('*').maybeSingle();
|
||||
if (error) {
|
||||
return NextResponse.json({ error: error.message }, { status: 500 });
|
||||
}
|
||||
return NextResponse.json({ settings: data });
|
||||
return NextResponse.json({
|
||||
settings: data || { host: '', port: 587, secure: false, user: '', pass: '' }
|
||||
});
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
@@ -86,8 +88,7 @@ export async function POST(request: Request) {
|
||||
const payload = await request.json(); // expect {host, port, secure, user, pass}
|
||||
const { error } = await supabase
|
||||
.from('settings')
|
||||
.upsert({ id: 'smtp', ...payload })
|
||||
.single();
|
||||
.upsert({ id: 'smtp', ...payload });
|
||||
if (error) {
|
||||
return NextResponse.json({ error: error.message }, { status: 500 });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user