Skip to content

Commit 9dd57ff

Browse files
committed
fix(client): verify email via Payload Local API to bypass basic auth
The verify-email server action was calling the Payload REST SDK against NEXT_PUBLIC_URL, so the request looped back through Next.js middleware. Local dev (and any env without auth creds in the public URL) hits the BASIC_AUTH gate and gets a 401 "Authentication required" before reaching Payload, leaving the user on the verification error page. Switch to the Payload Local API (getPayload + payload.verifyEmail). No HTTP roundtrip, no middleware, works in every env regardless of how basic auth is wired.
1 parent 5a25176 commit 9dd57ff

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

  • client/src/app/(frontend)/[locale]/(app)/auth/verify-email

client/src/app/(frontend)/[locale]/(app)/auth/verify-email/actions.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"use server";
22

3-
import { sdk } from "@/services/sdk";
3+
import { getPayload } from "payload";
4+
5+
import config from "@/payload.config";
46

57
export type VerifyEmailResult =
68
| { success: true }
@@ -12,14 +14,13 @@ export async function verifyEmailAction(token: string): Promise<VerifyEmailResul
1214
}
1315

1416
try {
15-
await sdk.verifyEmail({
16-
collection: "users",
17-
token,
18-
});
17+
const payload = await getPayload({ config });
18+
await payload.verifyEmail({ collection: "users", token });
1919
return { success: true };
2020
} catch (error) {
2121
const message = error instanceof Error ? error.message : String(error);
22-
const isInvalid = /invalid/i.test(message) || /403/.test(message);
22+
const status = (error as { status?: number } | null)?.status;
23+
const isInvalid = status === 403 || /invalid/i.test(message);
2324

2425
console.error("[verify-email] verification failed", {
2526
reason: isInvalid ? "invalid" : "unknown",

0 commit comments

Comments
 (0)