Skip to content

Commit 4e844f6

Browse files
authored
Merge pull request #82 from DataScience-GT/refactor/routes
yeah
2 parents ccafe98 + 7b40ec5 commit 4e844f6

2 files changed

Lines changed: 19 additions & 19 deletions

File tree

packages/auth/src/config.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,16 @@ export const authConfig: NextAuthConfig = {
9696
const { createTransport } = await import("nodemailer");
9797
const transport = createTransport(provider.server);
9898

99-
// Parse the NextAuth callback URL to extract token and callbackUrl
10099
const parsedUrl = new URL(url);
101100
const host = parsedUrl.host;
102-
const token = parsedUrl.searchParams.get("token") || "";
103-
const callbackUrl = parsedUrl.searchParams.get("callbackUrl") || "/dashboard";
104101

105102
// Build an intermediate /verify URL that prevents email scanners
106-
// from consuming the one-time token via pre-fetch GET requests
103+
// from consuming the one-time token via pre-fetch GET requests.
104+
// We pass the ENTIRE original callback URL encoded to avoid
105+
// dropping any parameters NextAuth needs internally.
107106
const verifyUrl = new URL("/verify", parsedUrl.origin);
108-
verifyUrl.searchParams.set("token", token);
107+
verifyUrl.searchParams.set("callback", Buffer.from(url).toString("base64"));
109108
verifyUrl.searchParams.set("email", identifier);
110-
verifyUrl.searchParams.set("callbackUrl", callbackUrl);
111109
const safeUrl = verifyUrl.toString();
112110

113111
const result = await transport.sendMail({

sites/mainweb/app/(portal)/verify/page.tsx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,22 @@ function VerifyContent() {
88
const searchParams = useSearchParams();
99
const [verifying, setVerifying] = useState(false);
1010

11-
// Build the actual NextAuth callback URL from the search params
12-
const callbackUrl = searchParams?.get('callbackUrl') || '/dashboard';
13-
const token = searchParams?.get('token') || '';
11+
// The full NextAuth callback URL is base64-encoded in the 'callback' param
12+
const encodedCallback = searchParams?.get('callback') || '';
1413
const email = searchParams?.get('email') || '';
1514

15+
let callbackUrl = '';
16+
try {
17+
callbackUrl = atob(encodedCallback);
18+
} catch {
19+
// invalid base64
20+
}
21+
1622
const handleVerify = () => {
23+
if (!callbackUrl) return;
1724
setVerifying(true);
18-
// Redirect to the actual NextAuth email callback
19-
const params = new URLSearchParams({
20-
callbackUrl,
21-
token,
22-
email,
23-
});
24-
window.location.href = `/api/auth/callback/nodemailer?${params.toString()}`;
25+
// Redirect to the exact original NextAuth callback URL
26+
window.location.href = callbackUrl;
2527
};
2628

2729
return (
@@ -55,16 +57,16 @@ function VerifyContent() {
5557
<div className="relative z-10">
5658
<button
5759
onClick={handleVerify}
58-
disabled={verifying || !token}
60+
disabled={verifying || !callbackUrl}
5961
className="px-12 py-5 bg-gradient-to-r from-emerald-600 to-emerald-500 text-white font-black text-xs uppercase tracking-[0.3em] hover:from-emerald-500 hover:to-emerald-400 transition-all rounded-lg shadow-[0_0_30px_rgba(16,185,129,0.2)] disabled:opacity-30 active:scale-95"
6062
>
6163
{verifying ? 'Verifying...' : 'Complete Sign In'}
6264
</button>
6365
</div>
6466

65-
{!token && (
67+
{!callbackUrl && (
6668
<p className="relative z-10 mt-8 text-red-500/70 font-mono text-xs">
67-
Error: No verification token found. Please request a new sign-in link.
69+
Error: Invalid or missing verification link. Please request a new sign-in link.
6870
</p>
6971
)}
7072

0 commit comments

Comments
 (0)