see comments

This commit is contained in:
Rajpreet0 2026-06-11 20:02:43 +02:00
parent b882094601
commit cc329b2ccb
2 changed files with 20 additions and 4 deletions

View file

@ -5,7 +5,9 @@ import { syncEmailAfterConfirmation } from "@/src/modules/settings/actions/perso
export async function GET(request: NextRequest) {
const { searchParams } = request.nextUrl;
const code = searchParams.get("code");
const next = searchParams.get("next") ?? "/settings/personal";
const requestedNext = searchParams.get("next");
const next =
requestedNext && /^\/(?!\/)/.test(requestedNext) ? requestedNext : "/settings/personal";
const isEmailChange = searchParams.get("email_confirmed") === "true";
if (!code) {
@ -20,7 +22,12 @@ export async function GET(request: NextRequest) {
}
if (isEmailChange) {
await syncEmailAfterConfirmation();
const syncResult = await syncEmailAfterConfirmation();
if (!syncResult.success) {
const fallback = new URL("/settings/personal", request.url);
fallback.searchParams.set("emailSync", "failed");
return NextResponse.redirect(fallback);
}
}
// Hard redirect so the browser re-fetches the page fully,

View file

@ -93,7 +93,10 @@ export async function updateEmail(newEmail: string): Promise<ActionResult> {
return { success: false, error: "Ungültige E-Mail-Adresse." };
}
const baseUrl = process.env.NEXT_PUBLIC_APP_URL ?? "http://localhost:3000";
const baseUrl = process.env.NEXT_PUBLIC_APP_URL;
if (!baseUrl) {
return { success: false, error: "App-URL ist nicht konfiguriert." };
}
const supabase = await createClient();
const { error: authError } = await supabase.auth.updateUser(
{ email: newEmail },
@ -133,7 +136,13 @@ export async function syncEmailAfterConfirmation(): Promise<ActionResult> {
if (manager) {
await prisma.manager.update({ where: { id }, data: { email: newEmail } });
} else {
await prisma.employee.updateMany({ where: { id }, data: { email: newEmail } });
const result = await prisma.employee.updateMany({
where: { id },
data: { email: newEmail },
});
if (result.count === 0) {
return { success: false, error: "Kein passender Datensatz für E-Mail-Sync gefunden." };
}
}
}