cauthy-auth 0.16.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.mts +15 -2
- package/dist/client.d.ts +15 -2
- package/dist/client.js +3 -2
- package/dist/client.js.map +1 -1
- package/dist/client.mjs +3 -2
- package/dist/client.mjs.map +1 -1
- package/dist/index.js +9 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9 -6
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +21 -2
- package/dist/react.d.ts +21 -2
- package/dist/react.js +12 -8
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +12 -8
- package/dist/react.mjs.map +1 -1
- package/dist/svelte.js +3 -2
- package/dist/svelte.js.map +1 -1
- package/dist/svelte.mjs +3 -2
- package/dist/svelte.mjs.map +1 -1
- package/dist/vue.js +3 -2
- package/dist/vue.js.map +1 -1
- package/dist/vue.mjs +3 -2
- package/dist/vue.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1083,12 +1083,12 @@ function createCauthy(given = {}) {
|
|
|
1083
1083
|
if (r.session === null) return { response: problem(401, "unauthenticated", "Sign in first.", void 0, headers) };
|
|
1084
1084
|
return { token: r.session.accessToken, kept: r.cookies.length === 0 ? (await read(request)).value : null, headers };
|
|
1085
1085
|
}
|
|
1086
|
-
async function signedIn(request, tokens, extra = []) {
|
|
1086
|
+
async function signedIn(request, tokens, extra = [], more = {}) {
|
|
1087
1087
|
const s = await stored(tokens);
|
|
1088
1088
|
if (s === null) return problem(502, "unavailable", "Sign-in is unavailable right now. Try again in a moment.");
|
|
1089
1089
|
const h = new Headers();
|
|
1090
1090
|
for (const c of [...await write(request, s, readCookies(request.headers.get("cookie"))), ...extra]) h.append("set-cookie", c);
|
|
1091
|
-
return json({ status: "signed_in", session: await toPublic(toSession(s)) }, 200, h);
|
|
1091
|
+
return json({ status: "signed_in", session: await toPublic(toSession(s)), ...more }, 200, h);
|
|
1092
1092
|
}
|
|
1093
1093
|
let lookCache = null;
|
|
1094
1094
|
async function ownRoute(request, url, route) {
|
|
@@ -1469,7 +1469,8 @@ function createCauthy(given = {}) {
|
|
|
1469
1469
|
return json({ status: "verified" });
|
|
1470
1470
|
}
|
|
1471
1471
|
if (route === "/sign-in/passkey/begin") {
|
|
1472
|
-
const
|
|
1472
|
+
const email = typeof b.email === "string" && checkEmail(b.email) === null ? b.email.trim() : "";
|
|
1473
|
+
const res = await ask(request, "POST", "/v1/auth/webauthn/login/begin", email !== "" ? { email } : {});
|
|
1473
1474
|
if (res.error) return problem(res.status, res.error.code, res.error.message);
|
|
1474
1475
|
const step = { kind: "passkey", token: String(res.data?.session_id ?? ""), returnTo: afterSignIn };
|
|
1475
1476
|
return json(
|
|
@@ -1507,8 +1508,10 @@ function createCauthy(given = {}) {
|
|
|
1507
1508
|
if (bad) return invalid(bad);
|
|
1508
1509
|
if (pages.signIn === void 0) return problem(500, "not_configured", "cauthy-auth: pages.signIn is required for sign-in links: it is the page the link opens");
|
|
1509
1510
|
const email = String(b.email).trim();
|
|
1510
|
-
|
|
1511
|
-
const
|
|
1511
|
+
const back = typeof b.returnTo === "string" ? localPath(b.returnTo, afterSignIn) : afterSignIn;
|
|
1512
|
+
const page = back === afterSignIn ? pages.signIn : `${pages.signIn}${pages.signIn.includes("?") ? "&" : "?"}return_to=${encodeURIComponent(back)}`;
|
|
1513
|
+
await ask(request, "POST", "/v1/auth/magic-link/request", { email, ...b.create === true ? { create_account: true } : {} }, page);
|
|
1514
|
+
const step = { kind: "code", token: email, returnTo: back };
|
|
1512
1515
|
return json({ status: "sent" }, 200, new Headers({ "set-cookie": writeCookie(stepCookie, await seal(step, await key), attrs(request, STEP_SECONDS)) }));
|
|
1513
1516
|
}
|
|
1514
1517
|
if (route === "/sign-in/email-code") {
|
|
@@ -1519,7 +1522,7 @@ function createCauthy(given = {}) {
|
|
|
1519
1522
|
if (step === null || step.kind !== "code") return problem(400, "step_expired", "Ask for a new link: this one was asked for too long ago.");
|
|
1520
1523
|
const res = await ask(request, "POST", "/v1/auth/magic-link/verify-code", { email: step.token, code: String(b.code).trim() });
|
|
1521
1524
|
if (res.error) return problem(res.status, res.error.code, res.error.message, "code");
|
|
1522
|
-
return signedIn(request, res.data, [writeCookie(stepCookie, "", attrs(request, 0))]);
|
|
1525
|
+
return signedIn(request, res.data, [writeCookie(stepCookie, "", attrs(request, 0))], { returnTo: step.returnTo });
|
|
1523
1526
|
}
|
|
1524
1527
|
if (route === "/sign-in/magic-link/verify") {
|
|
1525
1528
|
if (!isToken(b.token)) return badLink();
|