faire-auth 1.0.3 → 1.1.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/{adapter-factory-lKIOf2OR.mjs → adapter-factory-qPVW8x9-.mjs} +34 -36
- package/dist/{adapter-factory-D1I7joki.cjs → adapter-factory-u8r3oTez.cjs} +66 -68
- package/dist/adapters/drizzle-adapter/index.cjs +34 -40
- package/dist/adapters/drizzle-adapter/index.d.cts +4 -9
- package/dist/adapters/drizzle-adapter/index.d.mts +4 -9
- package/dist/adapters/drizzle-adapter/index.mjs +20 -26
- package/dist/adapters/index.cjs +11 -16
- package/dist/adapters/index.d.cts +11 -37
- package/dist/adapters/index.d.mts +11 -37
- package/dist/adapters/index.mjs +4 -13
- package/dist/adapters/kysely-adapter/index.cjs +270 -11
- package/dist/adapters/kysely-adapter/index.d.cts +9 -19
- package/dist/adapters/kysely-adapter/index.d.mts +9 -19
- package/dist/adapters/kysely-adapter/index.mjs +267 -9
- package/dist/adapters/memory-adapter/index.cjs +146 -9
- package/dist/adapters/memory-adapter/index.d.cts +4 -10
- package/dist/adapters/memory-adapter/index.d.mts +4 -10
- package/dist/adapters/memory-adapter/index.mjs +145 -9
- package/dist/adapters/mongodb-adapter/index.cjs +13 -21
- package/dist/adapters/mongodb-adapter/index.d.cts +3 -8
- package/dist/adapters/mongodb-adapter/index.d.mts +4 -9
- package/dist/adapters/mongodb-adapter/index.mjs +12 -20
- package/dist/adapters/prisma-adapter/index.cjs +12 -20
- package/dist/adapters/prisma-adapter/index.d.cts +4 -8
- package/dist/adapters/prisma-adapter/index.d.mts +4 -8
- package/dist/adapters/prisma-adapter/index.mjs +5 -13
- package/dist/adapters/test.cjs +86 -69
- package/dist/adapters/test.d.cts +7 -11
- package/dist/adapters/test.d.mts +7 -11
- package/dist/adapters/test.mjs +83 -66
- package/dist/api/index.cjs +3 -20
- package/dist/api/index.d.cts +2 -3
- package/dist/api/index.d.mts +2 -3
- package/dist/api/index.mjs +1 -20
- package/dist/api/middleware/index.cjs +4 -11
- package/dist/api/middleware/index.d.cts +3 -9
- package/dist/api/middleware/index.d.mts +3 -9
- package/dist/api/middleware/index.mjs +3 -11
- package/dist/{api-B4RDwBty.mjs → api-0f-F-Fi2.mjs} +292 -189
- package/dist/{api-CaRC1Gio.cjs → api-LjfH6hQi.cjs} +557 -452
- package/dist/{test-utils/bun-sqlite-dialect-BZBvHchL.cjs → bun-sqlite-dialect-BHkarnxN.cjs} +5 -9
- package/dist/{test-utils/bun-sqlite-dialect-BSWhhKNs.mjs → bun-sqlite-dialect-BiZBuEF6.mjs} +6 -9
- package/dist/client/index.cjs +8 -15
- package/dist/client/index.d.cts +9 -14
- package/dist/client/index.d.mts +9 -14
- package/dist/client/index.mjs +7 -15
- package/dist/client/lynx/index.cjs +10 -18
- package/dist/client/lynx/index.d.cts +402 -71
- package/dist/client/lynx/index.d.mts +402 -71
- package/dist/client/lynx/index.mjs +5 -13
- package/dist/client/plugins/index.cjs +3 -5
- package/dist/client/plugins/index.d.cts +5 -10
- package/dist/client/plugins/index.d.mts +5 -10
- package/dist/client/plugins/index.mjs +2 -4
- package/dist/client/react/index.cjs +6 -14
- package/dist/client/react/index.d.cts +402 -71
- package/dist/client/react/index.d.mts +402 -71
- package/dist/client/react/index.mjs +5 -13
- package/dist/client/solid/index.cjs +6 -14
- package/dist/client/solid/index.d.cts +393 -57
- package/dist/client/solid/index.d.mts +393 -57
- package/dist/client/solid/index.mjs +5 -13
- package/dist/client/svelte/index.cjs +5 -10
- package/dist/client/svelte/index.d.cts +400 -67
- package/dist/client/svelte/index.d.mts +400 -67
- package/dist/client/svelte/index.mjs +4 -10
- package/dist/client/vue/index.cjs +6 -14
- package/dist/client/vue/index.d.cts +401 -68
- package/dist/client/vue/index.d.mts +401 -68
- package/dist/client/vue/index.mjs +5 -13
- package/dist/{cookies-BTs1o992.mjs → cookies-D9aY_gJh.mjs} +25 -21
- package/dist/{cookies-BTl72THv.cjs → cookies-DQ52rcOy.cjs} +119 -115
- package/dist/crypto/index.cjs +10 -8
- package/dist/crypto/index.d.cts +5 -13
- package/dist/crypto/index.d.mts +5 -13
- package/dist/crypto/index.mjs +2 -5
- package/dist/{crypto-DH2Aa7jN.mjs → crypto-BH-hD0lJ.mjs} +7 -10
- package/dist/{crypto-DpSCnrTp.cjs → crypto-BITfWVwD.cjs} +24 -27
- package/dist/db/index.cjs +1135 -29
- package/dist/db/index.d.cts +1 -2
- package/dist/db/index.d.mts +1 -2
- package/dist/db/index.mjs +1115 -16
- package/dist/defu-D2h4S3X-.mjs +87 -0
- package/dist/defu-DWS5RPWt.cjs +134 -0
- package/dist/{email-verification-DI_0H4JC.cjs → email-verification-DOPnSgbI.cjs} +65 -71
- package/dist/{email-verification-C_lBu_JY.mjs → email-verification-YSR5n5lb.mjs} +23 -29
- package/dist/{hono-CO-zsqI-.mjs → hono-BAV2wQkK.mjs} +16 -33
- package/dist/hono-SVQuc5Ru.mjs +4 -0
- package/dist/hono-pgK4H_U1.cjs +9 -0
- package/dist/{hono-DnW5crl1.cjs → hono-tyFFJFdS.cjs} +42 -60
- package/dist/index-B86Cy0dE.d.cts +2 -0
- package/dist/index-B86Cy0dE.d.mts +2 -0
- package/dist/index.cjs +115 -150
- package/dist/index.d.cts +4 -5
- package/dist/index.d.mts +4 -5
- package/dist/index.mjs +46 -81
- package/dist/integrations/next-js.cjs +5 -9
- package/dist/integrations/next-js.d.cts +6 -14
- package/dist/integrations/next-js.d.mts +6 -14
- package/dist/integrations/next-js.mjs +4 -9
- package/dist/integrations/node.cjs +16 -14
- package/dist/integrations/node.d.cts +6 -14
- package/dist/integrations/node.d.mts +6 -14
- package/dist/integrations/node.mjs +15 -13
- package/dist/integrations/react-start.cjs +7 -11
- package/dist/integrations/react-start.d.cts +5 -13
- package/dist/integrations/react-start.d.mts +5 -13
- package/dist/integrations/react-start.mjs +6 -11
- package/dist/integrations/solid-start.cjs +3 -5
- package/dist/integrations/solid-start.d.cts +2 -5
- package/dist/integrations/solid-start.d.mts +2 -5
- package/dist/integrations/solid-start.mjs +2 -4
- package/dist/integrations/svelte-kit.cjs +6 -10
- package/dist/integrations/svelte-kit.d.cts +11 -23
- package/dist/integrations/svelte-kit.d.mts +11 -23
- package/dist/integrations/svelte-kit.mjs +5 -10
- package/dist/{ip-BjNYspCH.mjs → ip-6Lv2o42m.mjs} +4 -9
- package/dist/{ip-C17Qdq-G.cjs → ip-DPydExzV.cjs} +21 -27
- package/dist/{json--tl7Grvs.cjs → json-D3aq-nH2.cjs} +9 -13
- package/dist/{json-B1v2qRTQ.mjs → json-DooGMtnJ.mjs} +2 -5
- package/dist/{logged-CyGfp8_H.mjs → logged-B83SzMnJ.mjs} +6 -10
- package/dist/{logged-Dv3st5qc.cjs → logged-BIpCpnVY.cjs} +13 -18
- package/dist/{middleware-CE6OhDkq.mjs → middleware-Cakg4e1D.mjs} +2 -4
- package/dist/{middleware-CWvRH4EW.cjs → middleware-Cd-VkNxB.cjs} +17 -20
- package/dist/{node-sqlite-dialect-w4DAg0PH.mjs → node-sqlite-dialect-BMVOjEMh.mjs} +6 -9
- package/dist/{test-utils/node-sqlite-dialect-BgJqjBOu.cjs → node-sqlite-dialect-D3QPFROH.cjs} +5 -9
- package/dist/oauth2/index.cjs +166 -22
- package/dist/oauth2/index.d.cts +5 -17
- package/dist/oauth2/index.d.mts +5 -17
- package/dist/oauth2/index.mjs +156 -16
- package/dist/{origin-check-DjLTuZQ8.cjs → origin-check-BflGhEEN.cjs} +34 -38
- package/dist/{origin-check-8Gajklvh.mjs → origin-check-CRgs1M7k.mjs} +13 -16
- package/dist/{parser-B25ylT5u.mjs → parser-CqwvpF6l.cjs} +12 -10
- package/dist/{parser-B_wxvaAr.cjs → parser-DcKDjjHO.mjs} +7 -22
- package/dist/plugins/access/index.cjs +38 -4
- package/dist/plugins/access/index.d.cts +36 -2
- package/dist/plugins/access/index.d.mts +36 -2
- package/dist/plugins/access/index.mjs +36 -3
- package/dist/plugins/bearer/index.cjs +52 -7
- package/dist/plugins/bearer/index.d.cts +27 -4
- package/dist/plugins/bearer/index.d.mts +27 -4
- package/dist/plugins/bearer/index.mjs +51 -7
- package/dist/plugins/index.cjs +1385 -842
- package/dist/plugins/index.d.cts +489 -7566
- package/dist/plugins/index.d.mts +489 -7566
- package/dist/plugins/index.mjs +1118 -576
- package/dist/plugins/passkey/index.cjs +551 -15
- package/dist/plugins/passkey/index.d.cts +123 -4
- package/dist/plugins/passkey/index.d.mts +123 -4
- package/dist/plugins/passkey/index.mjs +547 -15
- package/dist/{chunk-BFnQceUY.mjs → rolldown-runtime-BKpuH2hG.mjs} +6 -7
- package/dist/{chunk-fPmz2rbM.cjs → rolldown-runtime-C_Pgydhf.cjs} +22 -24
- package/dist/{schema-DTIwLLmf.mjs → schema-CFCpv0tK.mjs} +3 -6
- package/dist/{schema-CirKflVs.cjs → schema-b-lKhMkG.cjs} +51 -55
- package/dist/{session-CM3rmOYF.mjs → session-BGjJgihS.mjs} +51 -74
- package/dist/{session-Cwrj4GfV.cjs → session-CzZSMmQC.cjs} +197 -219
- package/dist/shared.d.cts +1581 -0
- package/dist/shared.d.mts +1581 -0
- package/dist/social-providers/index.cjs +9 -9
- package/dist/social-providers/index.d.cts +1 -1
- package/dist/social-providers/index.d.mts +1 -1
- package/dist/social-providers/index.mjs +3 -5
- package/dist/social-providers-CjPww-qf.mjs +6 -0
- package/dist/social-providers-D7w_7Ym8.cjs +10 -0
- package/dist/{state-CvSihlVT.cjs → state-2OrNjOO-.cjs} +24 -24
- package/dist/{state-CQghgH9I.mjs → state-Dooeisfq.mjs} +17 -17
- package/dist/{bun-sqlite-dialect-DPgTzc0w.cjs → test-utils/bun-sqlite-dialect-BHkarnxN.cjs} +5 -9
- package/dist/{bun-sqlite-dialect-6NqeV3px.mjs → test-utils/bun-sqlite-dialect-BiZBuEF6.mjs} +6 -9
- package/dist/test-utils/index.cjs +8831 -7941
- package/dist/test-utils/index.d.cts +310 -12440
- package/dist/test-utils/index.d.mts +313 -12440
- package/dist/test-utils/index.mjs +8591 -7701
- package/dist/test-utils/{node-sqlite-dialect-DAQXiobH.mjs → node-sqlite-dialect-BMVOjEMh.mjs} +6 -9
- package/dist/{node-sqlite-dialect-DP11CB0y.cjs → test-utils/node-sqlite-dialect-D3QPFROH.cjs} +5 -9
- package/dist/types/index.d.cts +2 -3
- package/dist/types/index.d.mts +2 -3
- package/dist/types/index.mjs +1 -1
- package/dist/{url-BoUuoIwZ.mjs → url-CJtdrrUu.mjs} +12 -13
- package/dist/{url-Ce7CVaQD.cjs → url-DjCmCUHS.cjs} +42 -44
- package/dist/utils/cookies.cjs +29 -30
- package/dist/utils/cookies.d.cts +21 -25
- package/dist/utils/cookies.d.mts +20 -24
- package/dist/utils/cookies.mjs +2 -7
- package/dist/utils-C7OHyfHa.mjs +4 -0
- package/dist/utils-iX0Vy_UL.cjs +3 -0
- package/package.json +40 -30
- package/dist/access-BZ7-AbTM.cjs +0 -51
- package/dist/access-D0DRqUKC.mjs +0 -39
- package/dist/bearer-DDzrp5M7.cjs +0 -60
- package/dist/bearer-WZcs7gxL.mjs +0 -54
- package/dist/db-4tUsQJXd.mjs +0 -1119
- package/dist/db-ChMbb_U-.cjs +0 -1180
- package/dist/defu-BmOYq4PU.cjs +0 -34
- package/dist/defu-D9ZTXqlo.mjs +0 -28
- package/dist/hono-C14rpOEa.cjs +0 -13
- package/dist/hono-CoKYWnXA.mjs +0 -7
- package/dist/hono-D0VqxVy1.d.mts +0 -18
- package/dist/hono-DOM31WQz.d.cts +0 -18
- package/dist/index-BCTFWP_o.d.mts +0 -992
- package/dist/index-BDhhaE6Y.d.cts +0 -3
- package/dist/index-BVRfQy6L.d.mts +0 -992
- package/dist/index-Baarsq5J.d.mts +0 -33
- package/dist/index-By364WbF.d.cts +0 -992
- package/dist/index-BzWwMgxr.d.cts +0 -992
- package/dist/index-CF9iq55a.d.mts +0 -3
- package/dist/index-CJD2yB-W.d.cts +0 -33
- package/dist/index-CRt_fppq.d.mts +0 -41
- package/dist/index-CdLyn7qP.d.cts +0 -41
- package/dist/index-CsWF3f7U.d.cts +0 -13350
- package/dist/index-CzidsAyA.d.mts +0 -13350
- package/dist/index-DvW-GCcI.d.cts +0 -33
- package/dist/index-f-5OJ9yV.d.cts +0 -13350
- package/dist/index-rFv8Hxld.d.mts +0 -13350
- package/dist/index-ztVZPQdV.d.mts +0 -33
- package/dist/kysely-adapter-CtIdoHa8.mjs +0 -270
- package/dist/kysely-adapter-QZTx077T.cjs +0 -288
- package/dist/memory-adapter-17RZd5df.cjs +0 -154
- package/dist/memory-adapter-Dp4XdCZK.mjs +0 -148
- package/dist/oauth2-5RL4cVNS.cjs +0 -177
- package/dist/oauth2-C56wz-n9.mjs +0 -159
- package/dist/passkey-BTT-v5c-.cjs +0 -512
- package/dist/passkey-CzY_W2us.mjs +0 -505
- package/dist/request-1NL_1lyJ.mjs +0 -58
- package/dist/request-CPNlp-DK.cjs +0 -100
- package/dist/social-providers-B8RK5yqI.mjs +0 -9
- package/dist/social-providers-BmFOIIPk.cjs +0 -13
- package/dist/utils-44aDDP8f.cjs +0 -2
- package/dist/utils-D4vZd1-9.mjs +0 -4
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// src/utils/request.ts
|
|
2
|
+
const isPromise = (value) => value != null && typeof value.then === "function";
|
|
3
|
+
const normaliseHeaders = (source) => {
|
|
4
|
+
if (source == null) return new Headers();
|
|
5
|
+
let result;
|
|
6
|
+
result = typeof source === "function" ? source() : source;
|
|
7
|
+
if (isPromise(result)) return result.then((h) => new Headers(h));
|
|
8
|
+
return new Headers(result);
|
|
9
|
+
};
|
|
10
|
+
const toHeaders = (source) => {
|
|
11
|
+
if (source instanceof Headers || Array.isArray(source)) return new Headers(source);
|
|
12
|
+
const out = new Headers();
|
|
13
|
+
for (const [k, v] of Object.entries(source)) if (v !== void 0) out.set(k, v);
|
|
14
|
+
return out;
|
|
15
|
+
};
|
|
16
|
+
const mergeHeaders = (...sources) => {
|
|
17
|
+
const resolved = sources.filter((v) => v !== void 0).map((src) => src == null ? {} : typeof src === "function" ? src() : src);
|
|
18
|
+
if (!resolved.some((r) => isPromise(r))) {
|
|
19
|
+
const out = new Headers();
|
|
20
|
+
resolved.forEach((h) => toHeaders(h).forEach((v, k) => out.set(k, v)));
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
return async () => {
|
|
24
|
+
const out = new Headers();
|
|
25
|
+
for (const r of resolved) toHeaders(isPromise(r) ? await r : r).forEach((v, k) => out.set(k, v));
|
|
26
|
+
return out;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
const buildSearchParams = (query) => {
|
|
30
|
+
const searchParams = new URLSearchParams();
|
|
31
|
+
for (const [k, v] of Object.entries(query)) {
|
|
32
|
+
if (v === void 0) continue;
|
|
33
|
+
if (Array.isArray(v)) for (const v2 of v) searchParams.append(k, v2);
|
|
34
|
+
else searchParams.set(k, v);
|
|
35
|
+
}
|
|
36
|
+
return searchParams;
|
|
37
|
+
};
|
|
38
|
+
const removeIndexString = (urlString) => {
|
|
39
|
+
if (/^https?:\/\/[^\/]+?\/index$/.test(urlString)) return urlString.replace(/\/index$/, "/");
|
|
40
|
+
return urlString.replace(/\/index$/, "");
|
|
41
|
+
};
|
|
42
|
+
const replaceUrlParam = (urlString, params) => {
|
|
43
|
+
for (const [k, v] of Object.entries(params)) {
|
|
44
|
+
const reg = new RegExp("/?:" + k + "(?:{[^/]+})?\\??");
|
|
45
|
+
urlString = urlString.replace(reg, (substring) => v ? `${substring[0] === "/" ? "/" : ""}${v}` : "");
|
|
46
|
+
}
|
|
47
|
+
return urlString.replace(/^\/\//, "/");
|
|
48
|
+
};
|
|
49
|
+
const mergePath = (base, path) => {
|
|
50
|
+
if (base == null) return path;
|
|
51
|
+
base = base.replace(/\/+$/, "");
|
|
52
|
+
base = base + "/";
|
|
53
|
+
path = path.replace(/^\/+/, "");
|
|
54
|
+
return base + path;
|
|
55
|
+
};
|
|
56
|
+
const replaceUrlProtocol = (urlString, protocol) => {
|
|
57
|
+
switch (protocol) {
|
|
58
|
+
case "ws": return urlString.replace(/^https?/i, (match) => match.toLowerCase() === "https" ? "wss" : "ws");
|
|
59
|
+
case "http": return urlString.replace(/^wss?/i, (match) => match.toLowerCase() === "wss" ? "https" : "http");
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
// src/utils/defu.ts
|
|
63
|
+
const isPlainObject = (value) => {
|
|
64
|
+
if (value === null || typeof value !== "object") return false;
|
|
65
|
+
const prototype = Object.getPrototypeOf(value);
|
|
66
|
+
if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) return false;
|
|
67
|
+
if (Symbol.iterator in value) return false;
|
|
68
|
+
if (Symbol.toStringTag in value) return Object.prototype.toString.call(value) === "[object Module]";
|
|
69
|
+
return true;
|
|
70
|
+
};
|
|
71
|
+
const _defu = (baseObject, defaults, namespace = ".", merger) => {
|
|
72
|
+
if (!isPlainObject(defaults)) return _defu(baseObject, {}, namespace, merger);
|
|
73
|
+
const object = Object.assign({}, defaults);
|
|
74
|
+
for (const key in baseObject) {
|
|
75
|
+
if (key === "__proto__" || key === "constructor") continue;
|
|
76
|
+
const value = baseObject[key];
|
|
77
|
+
if (value === null || value === void 0) continue;
|
|
78
|
+
if (merger?.(object, key, value, namespace) != null) continue;
|
|
79
|
+
if (Array.isArray(value) && Array.isArray(object[key])) object[key] = [...value, ...object[key]];
|
|
80
|
+
else if (isPlainObject(value) && isPlainObject(object[key])) object[key] = _defu(value, object[key], (namespace ? `${namespace}.` : "") + key.toString(), merger);
|
|
81
|
+
else object[key] = value;
|
|
82
|
+
}
|
|
83
|
+
return object;
|
|
84
|
+
};
|
|
85
|
+
const createDefu = (merger) => (...arguments_) => arguments_.reduce((p, c) => _defu(p, c, "", merger), {});
|
|
86
|
+
const defu = createDefu();
|
|
87
|
+
export { normaliseHeaders as a, replaceUrlProtocol as c, mergePath as i, buildSearchParams as n, removeIndexString as o, mergeHeaders as r, replaceUrlParam as s, defu as t };
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// src/utils/request.ts
|
|
2
|
+
const isPromise = (value) => value != null && typeof value.then === "function";
|
|
3
|
+
const normaliseHeaders = (source) => {
|
|
4
|
+
if (source == null) return new Headers();
|
|
5
|
+
let result;
|
|
6
|
+
result = typeof source === "function" ? source() : source;
|
|
7
|
+
if (isPromise(result)) return result.then((h) => new Headers(h));
|
|
8
|
+
return new Headers(result);
|
|
9
|
+
};
|
|
10
|
+
const toHeaders = (source) => {
|
|
11
|
+
if (source instanceof Headers || Array.isArray(source)) return new Headers(source);
|
|
12
|
+
const out = new Headers();
|
|
13
|
+
for (const [k, v] of Object.entries(source)) if (v !== void 0) out.set(k, v);
|
|
14
|
+
return out;
|
|
15
|
+
};
|
|
16
|
+
const mergeHeaders = (...sources) => {
|
|
17
|
+
const resolved = sources.filter((v) => v !== void 0).map((src) => src == null ? {} : typeof src === "function" ? src() : src);
|
|
18
|
+
if (!resolved.some((r) => isPromise(r))) {
|
|
19
|
+
const out = new Headers();
|
|
20
|
+
resolved.forEach((h) => toHeaders(h).forEach((v, k) => out.set(k, v)));
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
return async () => {
|
|
24
|
+
const out = new Headers();
|
|
25
|
+
for (const r of resolved) toHeaders(isPromise(r) ? await r : r).forEach((v, k) => out.set(k, v));
|
|
26
|
+
return out;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
const buildSearchParams = (query) => {
|
|
30
|
+
const searchParams = new URLSearchParams();
|
|
31
|
+
for (const [k, v] of Object.entries(query)) {
|
|
32
|
+
if (v === void 0) continue;
|
|
33
|
+
if (Array.isArray(v)) for (const v2 of v) searchParams.append(k, v2);
|
|
34
|
+
else searchParams.set(k, v);
|
|
35
|
+
}
|
|
36
|
+
return searchParams;
|
|
37
|
+
};
|
|
38
|
+
const removeIndexString = (urlString) => {
|
|
39
|
+
if (/^https?:\/\/[^\/]+?\/index$/.test(urlString)) return urlString.replace(/\/index$/, "/");
|
|
40
|
+
return urlString.replace(/\/index$/, "");
|
|
41
|
+
};
|
|
42
|
+
const replaceUrlParam = (urlString, params) => {
|
|
43
|
+
for (const [k, v] of Object.entries(params)) {
|
|
44
|
+
const reg = new RegExp("/?:" + k + "(?:{[^/]+})?\\??");
|
|
45
|
+
urlString = urlString.replace(reg, (substring) => v ? `${substring[0] === "/" ? "/" : ""}${v}` : "");
|
|
46
|
+
}
|
|
47
|
+
return urlString.replace(/^\/\//, "/");
|
|
48
|
+
};
|
|
49
|
+
const mergePath = (base, path) => {
|
|
50
|
+
if (base == null) return path;
|
|
51
|
+
base = base.replace(/\/+$/, "");
|
|
52
|
+
base = base + "/";
|
|
53
|
+
path = path.replace(/^\/+/, "");
|
|
54
|
+
return base + path;
|
|
55
|
+
};
|
|
56
|
+
const replaceUrlProtocol = (urlString, protocol) => {
|
|
57
|
+
switch (protocol) {
|
|
58
|
+
case "ws": return urlString.replace(/^https?/i, (match) => match.toLowerCase() === "https" ? "wss" : "ws");
|
|
59
|
+
case "http": return urlString.replace(/^wss?/i, (match) => match.toLowerCase() === "wss" ? "https" : "http");
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
// src/utils/defu.ts
|
|
63
|
+
const isPlainObject = (value) => {
|
|
64
|
+
if (value === null || typeof value !== "object") return false;
|
|
65
|
+
const prototype = Object.getPrototypeOf(value);
|
|
66
|
+
if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) return false;
|
|
67
|
+
if (Symbol.iterator in value) return false;
|
|
68
|
+
if (Symbol.toStringTag in value) return Object.prototype.toString.call(value) === "[object Module]";
|
|
69
|
+
return true;
|
|
70
|
+
};
|
|
71
|
+
const _defu = (baseObject, defaults, namespace = ".", merger) => {
|
|
72
|
+
if (!isPlainObject(defaults)) return _defu(baseObject, {}, namespace, merger);
|
|
73
|
+
const object = Object.assign({}, defaults);
|
|
74
|
+
for (const key in baseObject) {
|
|
75
|
+
if (key === "__proto__" || key === "constructor") continue;
|
|
76
|
+
const value = baseObject[key];
|
|
77
|
+
if (value === null || value === void 0) continue;
|
|
78
|
+
if (merger?.(object, key, value, namespace) != null) continue;
|
|
79
|
+
if (Array.isArray(value) && Array.isArray(object[key])) object[key] = [...value, ...object[key]];
|
|
80
|
+
else if (isPlainObject(value) && isPlainObject(object[key])) object[key] = _defu(value, object[key], (namespace ? `${namespace}.` : "") + key.toString(), merger);
|
|
81
|
+
else object[key] = value;
|
|
82
|
+
}
|
|
83
|
+
return object;
|
|
84
|
+
};
|
|
85
|
+
const createDefu = (merger) => (...arguments_) => arguments_.reduce((p, c) => _defu(p, c, "", merger), {});
|
|
86
|
+
const defu = createDefu();
|
|
87
|
+
Object.defineProperty(exports, "buildSearchParams", {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
get: function() {
|
|
90
|
+
return buildSearchParams;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
Object.defineProperty(exports, "defu", {
|
|
94
|
+
enumerable: true,
|
|
95
|
+
get: function() {
|
|
96
|
+
return defu;
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
Object.defineProperty(exports, "mergeHeaders", {
|
|
100
|
+
enumerable: true,
|
|
101
|
+
get: function() {
|
|
102
|
+
return mergeHeaders;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
Object.defineProperty(exports, "mergePath", {
|
|
106
|
+
enumerable: true,
|
|
107
|
+
get: function() {
|
|
108
|
+
return mergePath;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
Object.defineProperty(exports, "normaliseHeaders", {
|
|
112
|
+
enumerable: true,
|
|
113
|
+
get: function() {
|
|
114
|
+
return normaliseHeaders;
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
Object.defineProperty(exports, "removeIndexString", {
|
|
118
|
+
enumerable: true,
|
|
119
|
+
get: function() {
|
|
120
|
+
return removeIndexString;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
Object.defineProperty(exports, "replaceUrlParam", {
|
|
124
|
+
enumerable: true,
|
|
125
|
+
get: function() {
|
|
126
|
+
return replaceUrlParam;
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
Object.defineProperty(exports, "replaceUrlProtocol", {
|
|
130
|
+
enumerable: true,
|
|
131
|
+
get: function() {
|
|
132
|
+
return replaceUrlProtocol;
|
|
133
|
+
}
|
|
134
|
+
});
|
|
@@ -1,33 +1,30 @@
|
|
|
1
|
-
const
|
|
2
|
-
const require_crypto = require(
|
|
3
|
-
const require_cookies = require(
|
|
4
|
-
const require_middleware = require(
|
|
5
|
-
const require_session = require(
|
|
6
|
-
const require_origin_check = require(
|
|
7
|
-
let
|
|
8
|
-
let
|
|
9
|
-
let
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-C_Pgydhf.cjs");
|
|
2
|
+
const require_crypto = require("./crypto-BITfWVwD.cjs");
|
|
3
|
+
const require_cookies = require("./cookies-DQ52rcOy.cjs");
|
|
4
|
+
const require_middleware = require("./middleware-Cd-VkNxB.cjs");
|
|
5
|
+
const require_session = require("./session-CzZSMmQC.cjs");
|
|
6
|
+
const require_origin_check = require("./origin-check-BflGhEEN.cjs");
|
|
7
|
+
let _faire_auth_core_factory = require("@faire-auth/core/factory");
|
|
8
|
+
let _faire_auth_core_static = require("@faire-auth/core/static");
|
|
9
|
+
let _faire_auth_core_utils = require("@faire-auth/core/utils");
|
|
10
10
|
let zod = require("zod");
|
|
11
|
-
zod =
|
|
11
|
+
zod = require_rolldown_runtime.__toESM(zod, 1);
|
|
12
12
|
let jose = require("jose");
|
|
13
13
|
let jose_errors = require("jose/errors");
|
|
14
|
-
|
|
15
|
-
//#region src/api/schema/email-verification.ts
|
|
14
|
+
// src/api/schema/email-verification.ts
|
|
16
15
|
const sendVerificationEmailSchema = zod.object({
|
|
17
|
-
email:
|
|
18
|
-
callbackURL: (0,
|
|
16
|
+
email: _faire_auth_core_factory.emailSchema.openapi({ description: "The email to send the verification email to" }),
|
|
17
|
+
callbackURL: (0, _faire_auth_core_factory.callbackURLSchema)(true).openapi({ description: "The URL to use for email verification callback" })
|
|
19
18
|
});
|
|
20
19
|
const verifyEmailQuerySchema = zod.object({
|
|
21
20
|
token: zod.string().openapi({ description: "The token to verify the email" }),
|
|
22
|
-
callbackURL: (0,
|
|
21
|
+
callbackURL: (0, _faire_auth_core_factory.callbackURLSchema)(true).openapi({ description: "The URL to redirect to after email verification" })
|
|
23
22
|
});
|
|
24
23
|
const verifyEmailTokenSchema = zod.object({
|
|
25
|
-
email:
|
|
24
|
+
email: _faire_auth_core_factory.emailSchema,
|
|
26
25
|
updateTo: zod.string().optional()
|
|
27
26
|
});
|
|
28
|
-
|
|
29
|
-
//#endregion
|
|
30
|
-
//#region src/api/middleware/token-check.ts
|
|
27
|
+
// src/api/middleware/token-check.ts
|
|
31
28
|
const onError = async (ctx, error) => {
|
|
32
29
|
let code;
|
|
33
30
|
if (error === "missing_token") code = 400;
|
|
@@ -38,9 +35,9 @@ const onError = async (ctx, error) => {
|
|
|
38
35
|
return ctx.redirect(`${url}?error=${error}`, 302);
|
|
39
36
|
}
|
|
40
37
|
return ctx.render({
|
|
41
|
-
success:
|
|
38
|
+
success: _faire_auth_core_static.False,
|
|
42
39
|
code: error.toUpperCase(),
|
|
43
|
-
message: (0,
|
|
40
|
+
message: (0, _faire_auth_core_utils.capitalizeFirstLetter)(error.replaceAll("_", " "))
|
|
44
41
|
}, code);
|
|
45
42
|
};
|
|
46
43
|
const verifyToken = async (token, context) => {
|
|
@@ -62,16 +59,15 @@ const verifyToken = async (token, context) => {
|
|
|
62
59
|
const tokenCheck = (getValue, schema) => require_middleware.createMiddleware()(async (ctx, next) => {
|
|
63
60
|
const token = await getValue(ctx);
|
|
64
61
|
if (!token) return onError(ctx, "missing_token");
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
const context = ctx.get("context");
|
|
63
|
+
const res = await verifyToken(token, context);
|
|
64
|
+
if (typeof res === "string") return onError(ctx, res);
|
|
65
|
+
const dat = await schema.safeParseAsync(res.payload);
|
|
68
66
|
if (dat.success === false) return onError(ctx, "invalid_token");
|
|
69
67
|
ctx.set("token", dat.data);
|
|
70
68
|
return await next();
|
|
71
69
|
});
|
|
72
|
-
|
|
73
|
-
//#endregion
|
|
74
|
-
//#region src/api/routes/email-verification.ts
|
|
70
|
+
// src/api/routes/email-verification.ts
|
|
75
71
|
const createEmailVerificationToken = async (secret, email, updateTo, expiresIn = 3600) => {
|
|
76
72
|
return await (0, require_crypto.crypto_exports.signJWT)({
|
|
77
73
|
email: email.toLowerCase(),
|
|
@@ -86,7 +82,7 @@ const sendVerificationEmailFn = async (ctx, user, callbackURL = encodeURICompone
|
|
|
86
82
|
if (!options?.emailVerification?.sendVerificationEmail) {
|
|
87
83
|
context.logger.error("Verification email isn't enabled.");
|
|
88
84
|
return ctx.render({
|
|
89
|
-
success:
|
|
85
|
+
success: _faire_auth_core_static.False,
|
|
90
86
|
message: "Verification email isn't enabled"
|
|
91
87
|
}, 400);
|
|
92
88
|
}
|
|
@@ -98,20 +94,20 @@ const sendVerificationEmailFn = async (ctx, user, callbackURL = encodeURICompone
|
|
|
98
94
|
token
|
|
99
95
|
}, ctx);
|
|
100
96
|
};
|
|
101
|
-
const sendVerificationEmailRoute = (0,
|
|
102
|
-
operationId:
|
|
97
|
+
const sendVerificationEmailRoute = (0, _faire_auth_core_factory.createRoute)({
|
|
98
|
+
operationId: _faire_auth_core_static.Routes.SEND_VERIFICATION_EMAIL,
|
|
103
99
|
method: "post",
|
|
104
100
|
path: "/send-verification-email",
|
|
105
101
|
description: "Send a verification email to the user",
|
|
106
|
-
request: (0,
|
|
107
|
-
responses: (0,
|
|
102
|
+
request: (0, _faire_auth_core_factory.req)().bdy(sendVerificationEmailSchema).bld(),
|
|
103
|
+
responses: (0, _faire_auth_core_factory.res)(_faire_auth_core_static.SCHEMAS[_faire_auth_core_static.Definitions.SUCCESS].default).err(400).zod().bld()
|
|
108
104
|
});
|
|
109
105
|
const sendVerificationEmail = require_session.createEndpoint(sendVerificationEmailRoute, (options) => async (ctx) => {
|
|
110
106
|
const context = ctx.get("context");
|
|
111
107
|
if (!options.emailVerification?.sendVerificationEmail) {
|
|
112
108
|
context.logger.error("Verification email isn't enabled.");
|
|
113
109
|
return ctx.render({
|
|
114
|
-
success:
|
|
110
|
+
success: _faire_auth_core_static.False,
|
|
115
111
|
message: "Verification email isn't enabled"
|
|
116
112
|
}, 400);
|
|
117
113
|
}
|
|
@@ -119,29 +115,29 @@ const sendVerificationEmail = require_session.createEndpoint(sendVerificationEma
|
|
|
119
115
|
const session = await require_session.getSessionFromCtx(ctx);
|
|
120
116
|
if (session instanceof Response) {
|
|
121
117
|
const user = await context.internalAdapter.findUserByEmail(email);
|
|
122
|
-
if (!user) return ctx.render({ success:
|
|
118
|
+
if (!user) return ctx.render({ success: _faire_auth_core_static.True }, 200);
|
|
123
119
|
await sendVerificationEmailFn(ctx, user.user, callbackURL, options);
|
|
124
|
-
return ctx.render({ success:
|
|
120
|
+
return ctx.render({ success: _faire_auth_core_static.True }, 200);
|
|
125
121
|
}
|
|
126
122
|
if (session.user.emailVerified) return ctx.render({
|
|
127
|
-
success:
|
|
123
|
+
success: _faire_auth_core_static.False,
|
|
128
124
|
message: "You can only send a verification email to an unverified email"
|
|
129
125
|
}, 400);
|
|
130
126
|
if (session.user.email !== email) return ctx.render({
|
|
131
|
-
success:
|
|
127
|
+
success: _faire_auth_core_static.False,
|
|
132
128
|
message: "You can only send a verification email to your own email"
|
|
133
129
|
}, 400);
|
|
134
130
|
await sendVerificationEmailFn(ctx, session.user, callbackURL, options);
|
|
135
|
-
return ctx.render({ success:
|
|
131
|
+
return ctx.render({ success: _faire_auth_core_static.True }, 200);
|
|
136
132
|
});
|
|
137
|
-
const verifyEmailRoute = (0,
|
|
138
|
-
operationId:
|
|
133
|
+
const verifyEmailRoute = (0, _faire_auth_core_factory.createRoute)({
|
|
134
|
+
operationId: _faire_auth_core_static.Routes.VERIFY_EMAIL,
|
|
139
135
|
method: "get",
|
|
140
136
|
path: "/verify-email",
|
|
141
137
|
description: "Verify the email of the user",
|
|
142
138
|
middleware: [require_origin_check.originCheck((ctx) => ctx.req.query("callbackURL")), tokenCheck((ctx) => ctx.req.query("token"), verifyEmailTokenSchema)],
|
|
143
|
-
request: (0,
|
|
144
|
-
responses: (0,
|
|
139
|
+
request: (0, _faire_auth_core_factory.req)().qry(verifyEmailQuerySchema).bld(),
|
|
140
|
+
responses: (0, _faire_auth_core_factory.res)(_faire_auth_core_static.SCHEMAS[_faire_auth_core_static.Definitions.TOKEN_USER].default).err(401, "Invalid or expired token").err(500).rdr("Redirect to callback URL").zod().bld()
|
|
145
141
|
});
|
|
146
142
|
const verifyEmail = require_session.createEndpoint(verifyEmailRoute, (options) => async (ctx) => {
|
|
147
143
|
const { callbackURL } = ctx.req.valid("query");
|
|
@@ -153,9 +149,9 @@ const verifyEmail = require_session.createEndpoint(verifyEmailRoute, (options) =
|
|
|
153
149
|
return ctx.redirect(`${callbackURL}?error=${error}`, 302);
|
|
154
150
|
}
|
|
155
151
|
return ctx.render({
|
|
156
|
-
success:
|
|
152
|
+
success: _faire_auth_core_static.False,
|
|
157
153
|
code: error.toUpperCase(),
|
|
158
|
-
message: (0,
|
|
154
|
+
message: (0, _faire_auth_core_utils.capitalizeFirstLetter)(error.replaceAll("_", " "))
|
|
159
155
|
}, 401);
|
|
160
156
|
};
|
|
161
157
|
const user = await context.internalAdapter.findUserByEmail(parsed.email);
|
|
@@ -163,17 +159,17 @@ const verifyEmail = require_session.createEndpoint(verifyEmailRoute, (options) =
|
|
|
163
159
|
if (parsed.updateTo) {
|
|
164
160
|
const session = await require_session.getSessionFromCtx(ctx);
|
|
165
161
|
if (session instanceof Response || session.user.email !== parsed.email) return redirectOnError("unauthorized");
|
|
166
|
-
const updatedUser
|
|
162
|
+
const updatedUser = await context.internalAdapter.updateUserByEmail(parsed.email, {
|
|
167
163
|
email: parsed.updateTo,
|
|
168
164
|
emailVerified: false
|
|
169
165
|
});
|
|
170
|
-
if (updatedUser
|
|
171
|
-
success:
|
|
166
|
+
if (updatedUser == null) return ctx.render({
|
|
167
|
+
success: _faire_auth_core_static.False,
|
|
172
168
|
message: "Failed to update user"
|
|
173
169
|
}, 500);
|
|
174
170
|
const newToken = await createEmailVerificationToken(context.secret, parsed.updateTo);
|
|
175
171
|
if (options.emailVerification?.sendVerificationEmail) await options.emailVerification.sendVerificationEmail({
|
|
176
|
-
user: updatedUser
|
|
172
|
+
user: updatedUser,
|
|
177
173
|
url: `${context.baseURL}/verify-email?token=${newToken}&callbackURL=${callbackURL ?? encodeURIComponent("/")}`,
|
|
178
174
|
token: newToken
|
|
179
175
|
}, ctx);
|
|
@@ -187,15 +183,15 @@ const verifyEmail = require_session.createEndpoint(verifyEmailRoute, (options) =
|
|
|
187
183
|
});
|
|
188
184
|
if (callbackURL != null) return ctx.redirect(callbackURL, 302);
|
|
189
185
|
return ctx.render({
|
|
190
|
-
success:
|
|
186
|
+
success: _faire_auth_core_static.True,
|
|
191
187
|
token: session.session.token,
|
|
192
|
-
user: updatedUser
|
|
188
|
+
user: updatedUser
|
|
193
189
|
}, 200);
|
|
194
190
|
}
|
|
195
191
|
if (options.emailVerification?.onEmailVerification) await options.emailVerification.onEmailVerification(user.user, ctx.req);
|
|
196
192
|
const updatedUser = await context.internalAdapter.updateUserByEmail(parsed.email, { emailVerified: true });
|
|
197
193
|
if (updatedUser == null) return ctx.render({
|
|
198
|
-
success:
|
|
194
|
+
success: _faire_auth_core_static.False,
|
|
199
195
|
message: "Failed to update user"
|
|
200
196
|
}, 500);
|
|
201
197
|
if (options.emailVerification?.afterEmailVerification) await options.emailVerification.afterEmailVerification(updatedUser, ctx.req);
|
|
@@ -204,7 +200,7 @@ const verifyEmail = require_session.createEndpoint(verifyEmailRoute, (options) =
|
|
|
204
200
|
if (currentSession instanceof Response || currentSession.user.email !== parsed.email) {
|
|
205
201
|
const session = await context.internalAdapter.createSession(user.user.id);
|
|
206
202
|
if (session == null) return ctx.render({
|
|
207
|
-
success:
|
|
203
|
+
success: _faire_auth_core_static.False,
|
|
208
204
|
message: "Failed to create session"
|
|
209
205
|
}, 500);
|
|
210
206
|
await require_cookies.setSessionCookie(ctx, options, {
|
|
@@ -223,25 +219,23 @@ const verifyEmail = require_session.createEndpoint(verifyEmailRoute, (options) =
|
|
|
223
219
|
});
|
|
224
220
|
}
|
|
225
221
|
if (callbackURL != null) return ctx.redirect(callbackURL, 302);
|
|
226
|
-
return ctx.render({ success:
|
|
222
|
+
return ctx.render({ success: _faire_auth_core_static.False }, 200);
|
|
227
223
|
});
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
return createEmailVerificationToken;
|
|
234
|
-
}
|
|
224
|
+
Object.defineProperty(exports, "createEmailVerificationToken", {
|
|
225
|
+
enumerable: true,
|
|
226
|
+
get: function() {
|
|
227
|
+
return createEmailVerificationToken;
|
|
228
|
+
}
|
|
235
229
|
});
|
|
236
|
-
Object.defineProperty(exports,
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
230
|
+
Object.defineProperty(exports, "sendVerificationEmail", {
|
|
231
|
+
enumerable: true,
|
|
232
|
+
get: function() {
|
|
233
|
+
return sendVerificationEmail;
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
Object.defineProperty(exports, "verifyEmail", {
|
|
237
|
+
enumerable: true,
|
|
238
|
+
get: function() {
|
|
239
|
+
return verifyEmail;
|
|
240
|
+
}
|
|
241
241
|
});
|
|
242
|
-
Object.defineProperty(exports, 'verifyEmail', {
|
|
243
|
-
enumerable: true,
|
|
244
|
-
get: function () {
|
|
245
|
-
return verifyEmail;
|
|
246
|
-
}
|
|
247
|
-
});
|
|
@@ -1,31 +1,28 @@
|
|
|
1
|
-
import { n as crypto_exports } from "./crypto-
|
|
2
|
-
import { y as setSessionCookie } from "./cookies-
|
|
3
|
-
import { r as createMiddleware } from "./middleware-
|
|
4
|
-
import { f as createEndpoint, r as getSessionFromCtx } from "./session-
|
|
5
|
-
import { n as originCheck } from "./origin-check-
|
|
1
|
+
import { n as crypto_exports } from "./crypto-BH-hD0lJ.mjs";
|
|
2
|
+
import { y as setSessionCookie } from "./cookies-D9aY_gJh.mjs";
|
|
3
|
+
import { r as createMiddleware } from "./middleware-Cakg4e1D.mjs";
|
|
4
|
+
import { f as createEndpoint, r as getSessionFromCtx } from "./session-BGjJgihS.mjs";
|
|
5
|
+
import { n as originCheck } from "./origin-check-CRgs1M7k.mjs";
|
|
6
6
|
import { callbackURLSchema, createRoute, emailSchema, req, res } from "@faire-auth/core/factory";
|
|
7
7
|
import { Definitions, False, Routes, SCHEMAS, True } from "@faire-auth/core/static";
|
|
8
8
|
import { capitalizeFirstLetter } from "@faire-auth/core/utils";
|
|
9
|
-
import * as z
|
|
9
|
+
import * as z from "zod";
|
|
10
10
|
import { jwtVerify } from "jose";
|
|
11
11
|
import { JWTExpired } from "jose/errors";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const sendVerificationEmailSchema = z$1.object({
|
|
12
|
+
// src/api/schema/email-verification.ts
|
|
13
|
+
const sendVerificationEmailSchema = z.object({
|
|
15
14
|
email: emailSchema.openapi({ description: "The email to send the verification email to" }),
|
|
16
15
|
callbackURL: callbackURLSchema(true).openapi({ description: "The URL to use for email verification callback" })
|
|
17
16
|
});
|
|
18
|
-
const verifyEmailQuerySchema = z
|
|
19
|
-
token: z
|
|
17
|
+
const verifyEmailQuerySchema = z.object({
|
|
18
|
+
token: z.string().openapi({ description: "The token to verify the email" }),
|
|
20
19
|
callbackURL: callbackURLSchema(true).openapi({ description: "The URL to redirect to after email verification" })
|
|
21
20
|
});
|
|
22
|
-
const verifyEmailTokenSchema = z
|
|
21
|
+
const verifyEmailTokenSchema = z.object({
|
|
23
22
|
email: emailSchema,
|
|
24
|
-
updateTo: z
|
|
23
|
+
updateTo: z.string().optional()
|
|
25
24
|
});
|
|
26
|
-
|
|
27
|
-
//#endregion
|
|
28
|
-
//#region src/api/middleware/token-check.ts
|
|
25
|
+
// src/api/middleware/token-check.ts
|
|
29
26
|
const onError = async (ctx, error) => {
|
|
30
27
|
let code;
|
|
31
28
|
if (error === "missing_token") code = 400;
|
|
@@ -60,16 +57,15 @@ const verifyToken = async (token, context) => {
|
|
|
60
57
|
const tokenCheck = (getValue, schema) => createMiddleware()(async (ctx, next) => {
|
|
61
58
|
const token = await getValue(ctx);
|
|
62
59
|
if (!token) return onError(ctx, "missing_token");
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
const context = ctx.get("context");
|
|
61
|
+
const res = await verifyToken(token, context);
|
|
62
|
+
if (typeof res === "string") return onError(ctx, res);
|
|
63
|
+
const dat = await schema.safeParseAsync(res.payload);
|
|
66
64
|
if (dat.success === false) return onError(ctx, "invalid_token");
|
|
67
65
|
ctx.set("token", dat.data);
|
|
68
66
|
return await next();
|
|
69
67
|
});
|
|
70
|
-
|
|
71
|
-
//#endregion
|
|
72
|
-
//#region src/api/routes/email-verification.ts
|
|
68
|
+
// src/api/routes/email-verification.ts
|
|
73
69
|
const createEmailVerificationToken = async (secret, email, updateTo, expiresIn = 3600) => {
|
|
74
70
|
return await (0, crypto_exports.signJWT)({
|
|
75
71
|
email: email.toLowerCase(),
|
|
@@ -161,17 +157,17 @@ const verifyEmail = createEndpoint(verifyEmailRoute, (options) => async (ctx) =>
|
|
|
161
157
|
if (parsed.updateTo) {
|
|
162
158
|
const session = await getSessionFromCtx(ctx);
|
|
163
159
|
if (session instanceof Response || session.user.email !== parsed.email) return redirectOnError("unauthorized");
|
|
164
|
-
const updatedUser
|
|
160
|
+
const updatedUser = await context.internalAdapter.updateUserByEmail(parsed.email, {
|
|
165
161
|
email: parsed.updateTo,
|
|
166
162
|
emailVerified: false
|
|
167
163
|
});
|
|
168
|
-
if (updatedUser
|
|
164
|
+
if (updatedUser == null) return ctx.render({
|
|
169
165
|
success: False,
|
|
170
166
|
message: "Failed to update user"
|
|
171
167
|
}, 500);
|
|
172
168
|
const newToken = await createEmailVerificationToken(context.secret, parsed.updateTo);
|
|
173
169
|
if (options.emailVerification?.sendVerificationEmail) await options.emailVerification.sendVerificationEmail({
|
|
174
|
-
user: updatedUser
|
|
170
|
+
user: updatedUser,
|
|
175
171
|
url: `${context.baseURL}/verify-email?token=${newToken}&callbackURL=${callbackURL ?? encodeURIComponent("/")}`,
|
|
176
172
|
token: newToken
|
|
177
173
|
}, ctx);
|
|
@@ -187,7 +183,7 @@ const verifyEmail = createEndpoint(verifyEmailRoute, (options) => async (ctx) =>
|
|
|
187
183
|
return ctx.render({
|
|
188
184
|
success: True,
|
|
189
185
|
token: session.session.token,
|
|
190
|
-
user: updatedUser
|
|
186
|
+
user: updatedUser
|
|
191
187
|
}, 200);
|
|
192
188
|
}
|
|
193
189
|
if (options.emailVerification?.onEmailVerification) await options.emailVerification.onEmailVerification(user.user, ctx.req);
|
|
@@ -223,6 +219,4 @@ const verifyEmail = createEndpoint(verifyEmailRoute, (options) => async (ctx) =>
|
|
|
223
219
|
if (callbackURL != null) return ctx.redirect(callbackURL, 302);
|
|
224
220
|
return ctx.render({ success: False }, 200);
|
|
225
221
|
});
|
|
226
|
-
|
|
227
|
-
//#endregion
|
|
228
|
-
export { sendVerificationEmail as n, verifyEmail as r, createEmailVerificationToken as t };
|
|
222
|
+
export { sendVerificationEmail as n, verifyEmail as r, createEmailVerificationToken as t };
|