Skip to content

Commit 1f27f1e

Browse files
ralyodioqwencoder
andcommitted
fix: pass email and phone to verify page on login so SMS auto-sends
The login page redirected to /auth/verify without email/phone params, so the verify page never auto-sent the SMS verification code. Now the login API returns the phone from user_profiles and the login page passes both email and phone as URL params to the verify page. Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
1 parent ee095b5 commit 1f27f1e

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

src/app/api/auth/login/route.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ export async function POST(req: NextRequest) {
1616
return NextResponse.json({ error: error.message }, { status: 401 });
1717
}
1818

19-
// Fetch profile for verification status
19+
// Fetch profile for verification status and phone number
2020
const admin = getSupabaseAdmin();
2121
const { data: profile } = await admin
2222
.from("user_profiles")
23-
.select("email_verified, phone_verified")
23+
.select("email_verified, phone_verified, phone")
2424
.eq("id", data.user.id)
2525
.single();
2626

@@ -31,6 +31,7 @@ export async function POST(req: NextRequest) {
3131
email: profile?.email_verified ?? false,
3232
phone: profile?.phone_verified ?? false,
3333
},
34+
phone: profile?.phone ?? null,
3435
});
3536
} catch (err) {
3637
console.error("Login error:", err);

src/app/auth/login/page.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ export default function LoginPage() {
4242

4343
const verified = data.verified || {};
4444
if (!verified.email || !verified.phone) {
45-
window.location.href = `/auth/verify?next=${encodeURIComponent(nextPath)}`;
45+
const params = new URLSearchParams({ next: nextPath });
46+
if (data.user?.email) params.set("email", data.user.email);
47+
if (data.phone) params.set("phone", data.phone);
48+
window.location.href = `/auth/verify?${params.toString()}`;
4649
} else {
4750
window.location.href = nextPath;
4851
}

0 commit comments

Comments
 (0)