Spend login, invite, and email-change links only after a confirm POST so mail scanners cannot use them up.
GET still shows a one-button page, a used invitation can resend or reopen for the signed-in invitee, and an email-change GET no longer signs the account out.
This commit is contained in:
1 parent
600056499c
commit
a725cf1a32
33 files changed
+1002
-89
No files matched your search
@@ -0,0 +1,31 @@
|
||||
import { NextRequest } from "next/server";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { readOneTimeLinkToken } from "../../lib/server/oneTimeLinkToken";
|
||||
|
||||
describe("readOneTimeLinkToken", () => {
|
||||
it("reads a token from the query string", async () => {
|
||||
const request = new NextRequest(
|
||||
"https://x.test/api/auth/magic-link/verify?token=abcdefghijkl",
|
||||
);
|
||||
await expect(readOneTimeLinkToken(request)).resolves.toBe("abcdefghijkl");
|
||||
});
|
||||
|
||||
it("returns null for a short query token", async () => {
|
||||
const request = new NextRequest(
|
||||
"https://x.test/api/auth/magic-link/verify?token=short",
|
||||
);
|
||||
await expect(readOneTimeLinkToken(request)).resolves.toBeNull();
|
||||
});
|
||||
|
||||
it("reads a token from a JSON body when the query is empty", async () => {
|
||||
const request = new NextRequest(
|
||||
"https://x.test/api/auth/magic-link/verify",
|
||||
{
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: JSON.stringify({ token: "abcdefghijkl" }),
|
||||
},
|
||||
);
|
||||
await expect(readOneTimeLinkToken(request)).resolves.toBe("abcdefghijkl");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user