faire-auth 1.0.4 → 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 +45 -80
- 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--DLiUhEn.d.mts +0 -33
- package/dist/index-B4bqEDYG.d.mts +0 -992
- package/dist/index-BDhhaE6Y.d.cts +0 -3
- package/dist/index-Boa0SV4h.d.cts +0 -13350
- package/dist/index-Bykgiq3o.d.cts +0 -13350
- package/dist/index-CF9iq55a.d.mts +0 -3
- package/dist/index-CRt_fppq.d.mts +0 -41
- package/dist/index-CdLyn7qP.d.cts +0 -41
- package/dist/index-ClFGA8tb.d.mts +0 -33
- package/dist/index-ClOM0wFf.d.cts +0 -992
- package/dist/index-CsxNfGAV.d.mts +0 -13350
- package/dist/index-DKnO_Zfm.d.cts +0 -992
- package/dist/index-DRYO4mGd.d.cts +0 -33
- package/dist/index-Dsua4U8w.d.cts +0 -33
- package/dist/index-DxXFCG2_.d.mts +0 -13350
- package/dist/index-gtCVvDvC.d.mts +0 -992
- 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
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-fPmz2rbM.cjs');
|
|
2
|
-
const require_adapter_factory = require('./adapter-factory-D1I7joki.cjs');
|
|
3
|
-
let __faire_auth_core_env = require("@faire-auth/core/env");
|
|
4
|
-
|
|
5
|
-
//#region src/adapters/memory-adapter/memory-adapter.ts
|
|
6
|
-
const memoryAdapter = (db, config) => {
|
|
7
|
-
let lazyOptions = null;
|
|
8
|
-
let adapterCreator = require_adapter_factory.createAdapterFactory({
|
|
9
|
-
config: {
|
|
10
|
-
adapterId: "memory",
|
|
11
|
-
adapterName: "Memory Adapter",
|
|
12
|
-
usePlural: false,
|
|
13
|
-
debugLogs: config?.debugLogs || false,
|
|
14
|
-
customTransformInput(props) {
|
|
15
|
-
if (props.options.advanced?.database?.useNumberId && props.field === "id" && props.action === "create") return db[props.model].length + 1;
|
|
16
|
-
return props.data;
|
|
17
|
-
},
|
|
18
|
-
transaction: async (cb) => {
|
|
19
|
-
let clone = structuredClone(db);
|
|
20
|
-
try {
|
|
21
|
-
return await cb(adapterCreator(lazyOptions));
|
|
22
|
-
} catch (error) {
|
|
23
|
-
Object.keys(db).forEach((key) => {
|
|
24
|
-
db[key] = clone[key];
|
|
25
|
-
});
|
|
26
|
-
throw error;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
adapter: ({ getFieldName, options, debugLog }) => {
|
|
31
|
-
function convertWhereClause(where, model) {
|
|
32
|
-
const table = db[model];
|
|
33
|
-
if (!table) {
|
|
34
|
-
__faire_auth_core_env.logger.error(`[MemoryAdapter] Model ${model} not found in the DB`, Object.keys(db));
|
|
35
|
-
throw new Error(`Model ${model} not found`);
|
|
36
|
-
}
|
|
37
|
-
const evalClause = (record, clause) => {
|
|
38
|
-
const { field, value, operator } = clause;
|
|
39
|
-
switch (operator) {
|
|
40
|
-
case "in":
|
|
41
|
-
if (!Array.isArray(value)) throw new Error("Value must be an array");
|
|
42
|
-
return value.includes(record[field]);
|
|
43
|
-
case "not_in":
|
|
44
|
-
if (!Array.isArray(value)) throw new Error("Value must be an array");
|
|
45
|
-
return !value.includes(record[field]);
|
|
46
|
-
case "contains": return record[field].includes(value);
|
|
47
|
-
case "starts_with": return record[field].startsWith(value);
|
|
48
|
-
case "ends_with": return record[field].endsWith(value);
|
|
49
|
-
case "ne": return record[field] !== value;
|
|
50
|
-
case "gt": return value != null && Boolean(record[field] > value);
|
|
51
|
-
case "gte": return value != null && Boolean(record[field] >= value);
|
|
52
|
-
case "lt": return value != null && Boolean(record[field] < value);
|
|
53
|
-
case "lte": return value != null && Boolean(record[field] <= value);
|
|
54
|
-
default: return record[field] === value;
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
return table.filter((record) => {
|
|
58
|
-
if (!where.length || where.length === 0) return true;
|
|
59
|
-
let result = evalClause(record, where[0]);
|
|
60
|
-
for (const clause of where) {
|
|
61
|
-
const clauseResult = evalClause(record, clause);
|
|
62
|
-
if (clause.connector === "OR") result = result || clauseResult;
|
|
63
|
-
else result = result && clauseResult;
|
|
64
|
-
}
|
|
65
|
-
return result;
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
return {
|
|
69
|
-
create: async ({ model, data }) => {
|
|
70
|
-
if (options.advanced?.database?.useNumberId) data.id = db[model].length + 1;
|
|
71
|
-
if (!db[model]) db[model] = [];
|
|
72
|
-
db[model].push(data);
|
|
73
|
-
return data;
|
|
74
|
-
},
|
|
75
|
-
findOne: async ({ model, where }) => {
|
|
76
|
-
return convertWhereClause(where, model)[0] || null;
|
|
77
|
-
},
|
|
78
|
-
findMany: async ({ model, where, sortBy, limit, offset }) => {
|
|
79
|
-
let table = db[model];
|
|
80
|
-
if (where) table = convertWhereClause(where, model);
|
|
81
|
-
if (sortBy) table = table.sort((a, b) => {
|
|
82
|
-
const field = getFieldName({
|
|
83
|
-
model,
|
|
84
|
-
field: sortBy.field
|
|
85
|
-
});
|
|
86
|
-
const aValue = a[field];
|
|
87
|
-
const bValue = b[field];
|
|
88
|
-
let comparison = 0;
|
|
89
|
-
if (aValue == null && bValue == null) comparison = 0;
|
|
90
|
-
else if (aValue == null) comparison = -1;
|
|
91
|
-
else if (bValue == null) comparison = 1;
|
|
92
|
-
else if (typeof aValue === "string" && typeof bValue === "string") comparison = aValue.localeCompare(bValue);
|
|
93
|
-
else if (aValue instanceof Date && bValue instanceof Date) comparison = aValue.getTime() - bValue.getTime();
|
|
94
|
-
else if (typeof aValue === "number" && typeof bValue === "number") comparison = aValue - bValue;
|
|
95
|
-
else if (typeof aValue === "boolean" && typeof bValue === "boolean") comparison = aValue === bValue ? 0 : aValue ? 1 : -1;
|
|
96
|
-
else comparison = String(aValue).localeCompare(String(bValue));
|
|
97
|
-
return sortBy.direction === "asc" ? comparison : -comparison;
|
|
98
|
-
});
|
|
99
|
-
if (offset !== void 0) table = table.slice(offset);
|
|
100
|
-
if (limit !== void 0) table = table.slice(0, limit);
|
|
101
|
-
return table || [];
|
|
102
|
-
},
|
|
103
|
-
count: async ({ model, where }) => {
|
|
104
|
-
if (where) return convertWhereClause(where, model).length;
|
|
105
|
-
return db[model].length;
|
|
106
|
-
},
|
|
107
|
-
update: async ({ model, where, update }) => {
|
|
108
|
-
const res = convertWhereClause(where, model);
|
|
109
|
-
res.forEach((record) => {
|
|
110
|
-
Object.assign(record, update);
|
|
111
|
-
});
|
|
112
|
-
return res[0] || null;
|
|
113
|
-
},
|
|
114
|
-
delete: async ({ model, where }) => {
|
|
115
|
-
const table = db[model];
|
|
116
|
-
const res = convertWhereClause(where, model);
|
|
117
|
-
db[model] = table.filter((record) => !res.includes(record));
|
|
118
|
-
},
|
|
119
|
-
deleteMany: async ({ model, where }) => {
|
|
120
|
-
const table = db[model];
|
|
121
|
-
const res = convertWhereClause(where, model);
|
|
122
|
-
let count = 0;
|
|
123
|
-
db[model] = table.filter((record) => {
|
|
124
|
-
if (res.includes(record)) {
|
|
125
|
-
count++;
|
|
126
|
-
return false;
|
|
127
|
-
}
|
|
128
|
-
return !res.includes(record);
|
|
129
|
-
});
|
|
130
|
-
return count;
|
|
131
|
-
},
|
|
132
|
-
updateMany({ model, where, update }) {
|
|
133
|
-
const res = convertWhereClause(where, model);
|
|
134
|
-
res.forEach((record) => {
|
|
135
|
-
Object.assign(record, update);
|
|
136
|
-
});
|
|
137
|
-
return res[0] || null;
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
return (options) => {
|
|
143
|
-
lazyOptions = options;
|
|
144
|
-
return adapterCreator(options);
|
|
145
|
-
};
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
//#endregion
|
|
149
|
-
Object.defineProperty(exports, 'memoryAdapter', {
|
|
150
|
-
enumerable: true,
|
|
151
|
-
get: function () {
|
|
152
|
-
return memoryAdapter;
|
|
153
|
-
}
|
|
154
|
-
});
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { t as createAdapterFactory } from "./adapter-factory-lKIOf2OR.mjs";
|
|
2
|
-
import { logger } from "@faire-auth/core/env";
|
|
3
|
-
|
|
4
|
-
//#region src/adapters/memory-adapter/memory-adapter.ts
|
|
5
|
-
const memoryAdapter = (db, config) => {
|
|
6
|
-
let lazyOptions = null;
|
|
7
|
-
let adapterCreator = createAdapterFactory({
|
|
8
|
-
config: {
|
|
9
|
-
adapterId: "memory",
|
|
10
|
-
adapterName: "Memory Adapter",
|
|
11
|
-
usePlural: false,
|
|
12
|
-
debugLogs: config?.debugLogs || false,
|
|
13
|
-
customTransformInput(props) {
|
|
14
|
-
if (props.options.advanced?.database?.useNumberId && props.field === "id" && props.action === "create") return db[props.model].length + 1;
|
|
15
|
-
return props.data;
|
|
16
|
-
},
|
|
17
|
-
transaction: async (cb) => {
|
|
18
|
-
let clone = structuredClone(db);
|
|
19
|
-
try {
|
|
20
|
-
return await cb(adapterCreator(lazyOptions));
|
|
21
|
-
} catch (error) {
|
|
22
|
-
Object.keys(db).forEach((key) => {
|
|
23
|
-
db[key] = clone[key];
|
|
24
|
-
});
|
|
25
|
-
throw error;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
adapter: ({ getFieldName, options, debugLog }) => {
|
|
30
|
-
function convertWhereClause(where, model) {
|
|
31
|
-
const table = db[model];
|
|
32
|
-
if (!table) {
|
|
33
|
-
logger.error(`[MemoryAdapter] Model ${model} not found in the DB`, Object.keys(db));
|
|
34
|
-
throw new Error(`Model ${model} not found`);
|
|
35
|
-
}
|
|
36
|
-
const evalClause = (record, clause) => {
|
|
37
|
-
const { field, value, operator } = clause;
|
|
38
|
-
switch (operator) {
|
|
39
|
-
case "in":
|
|
40
|
-
if (!Array.isArray(value)) throw new Error("Value must be an array");
|
|
41
|
-
return value.includes(record[field]);
|
|
42
|
-
case "not_in":
|
|
43
|
-
if (!Array.isArray(value)) throw new Error("Value must be an array");
|
|
44
|
-
return !value.includes(record[field]);
|
|
45
|
-
case "contains": return record[field].includes(value);
|
|
46
|
-
case "starts_with": return record[field].startsWith(value);
|
|
47
|
-
case "ends_with": return record[field].endsWith(value);
|
|
48
|
-
case "ne": return record[field] !== value;
|
|
49
|
-
case "gt": return value != null && Boolean(record[field] > value);
|
|
50
|
-
case "gte": return value != null && Boolean(record[field] >= value);
|
|
51
|
-
case "lt": return value != null && Boolean(record[field] < value);
|
|
52
|
-
case "lte": return value != null && Boolean(record[field] <= value);
|
|
53
|
-
default: return record[field] === value;
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
return table.filter((record) => {
|
|
57
|
-
if (!where.length || where.length === 0) return true;
|
|
58
|
-
let result = evalClause(record, where[0]);
|
|
59
|
-
for (const clause of where) {
|
|
60
|
-
const clauseResult = evalClause(record, clause);
|
|
61
|
-
if (clause.connector === "OR") result = result || clauseResult;
|
|
62
|
-
else result = result && clauseResult;
|
|
63
|
-
}
|
|
64
|
-
return result;
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
return {
|
|
68
|
-
create: async ({ model, data }) => {
|
|
69
|
-
if (options.advanced?.database?.useNumberId) data.id = db[model].length + 1;
|
|
70
|
-
if (!db[model]) db[model] = [];
|
|
71
|
-
db[model].push(data);
|
|
72
|
-
return data;
|
|
73
|
-
},
|
|
74
|
-
findOne: async ({ model, where }) => {
|
|
75
|
-
return convertWhereClause(where, model)[0] || null;
|
|
76
|
-
},
|
|
77
|
-
findMany: async ({ model, where, sortBy, limit, offset }) => {
|
|
78
|
-
let table = db[model];
|
|
79
|
-
if (where) table = convertWhereClause(where, model);
|
|
80
|
-
if (sortBy) table = table.sort((a, b) => {
|
|
81
|
-
const field = getFieldName({
|
|
82
|
-
model,
|
|
83
|
-
field: sortBy.field
|
|
84
|
-
});
|
|
85
|
-
const aValue = a[field];
|
|
86
|
-
const bValue = b[field];
|
|
87
|
-
let comparison = 0;
|
|
88
|
-
if (aValue == null && bValue == null) comparison = 0;
|
|
89
|
-
else if (aValue == null) comparison = -1;
|
|
90
|
-
else if (bValue == null) comparison = 1;
|
|
91
|
-
else if (typeof aValue === "string" && typeof bValue === "string") comparison = aValue.localeCompare(bValue);
|
|
92
|
-
else if (aValue instanceof Date && bValue instanceof Date) comparison = aValue.getTime() - bValue.getTime();
|
|
93
|
-
else if (typeof aValue === "number" && typeof bValue === "number") comparison = aValue - bValue;
|
|
94
|
-
else if (typeof aValue === "boolean" && typeof bValue === "boolean") comparison = aValue === bValue ? 0 : aValue ? 1 : -1;
|
|
95
|
-
else comparison = String(aValue).localeCompare(String(bValue));
|
|
96
|
-
return sortBy.direction === "asc" ? comparison : -comparison;
|
|
97
|
-
});
|
|
98
|
-
if (offset !== void 0) table = table.slice(offset);
|
|
99
|
-
if (limit !== void 0) table = table.slice(0, limit);
|
|
100
|
-
return table || [];
|
|
101
|
-
},
|
|
102
|
-
count: async ({ model, where }) => {
|
|
103
|
-
if (where) return convertWhereClause(where, model).length;
|
|
104
|
-
return db[model].length;
|
|
105
|
-
},
|
|
106
|
-
update: async ({ model, where, update }) => {
|
|
107
|
-
const res = convertWhereClause(where, model);
|
|
108
|
-
res.forEach((record) => {
|
|
109
|
-
Object.assign(record, update);
|
|
110
|
-
});
|
|
111
|
-
return res[0] || null;
|
|
112
|
-
},
|
|
113
|
-
delete: async ({ model, where }) => {
|
|
114
|
-
const table = db[model];
|
|
115
|
-
const res = convertWhereClause(where, model);
|
|
116
|
-
db[model] = table.filter((record) => !res.includes(record));
|
|
117
|
-
},
|
|
118
|
-
deleteMany: async ({ model, where }) => {
|
|
119
|
-
const table = db[model];
|
|
120
|
-
const res = convertWhereClause(where, model);
|
|
121
|
-
let count = 0;
|
|
122
|
-
db[model] = table.filter((record) => {
|
|
123
|
-
if (res.includes(record)) {
|
|
124
|
-
count++;
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
return !res.includes(record);
|
|
128
|
-
});
|
|
129
|
-
return count;
|
|
130
|
-
},
|
|
131
|
-
updateMany({ model, where, update }) {
|
|
132
|
-
const res = convertWhereClause(where, model);
|
|
133
|
-
res.forEach((record) => {
|
|
134
|
-
Object.assign(record, update);
|
|
135
|
-
});
|
|
136
|
-
return res[0] || null;
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
return (options) => {
|
|
142
|
-
lazyOptions = options;
|
|
143
|
-
return adapterCreator(options);
|
|
144
|
-
};
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
//#endregion
|
|
148
|
-
export { memoryAdapter as t };
|
package/dist/oauth2-5RL4cVNS.cjs
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-fPmz2rbM.cjs');
|
|
2
|
-
const require_crypto = require('./crypto-DpSCnrTp.cjs');
|
|
3
|
-
const require_email_verification = require('./email-verification-DI_0H4JC.cjs');
|
|
4
|
-
let __faire_auth_core_env = require("@faire-auth/core/env");
|
|
5
|
-
let __faire_auth_core_error = require("@faire-auth/core/error");
|
|
6
|
-
|
|
7
|
-
//#region src/oauth2/utils.ts
|
|
8
|
-
const decryptOAuthToken = (token, ctx, options) => {
|
|
9
|
-
if (!token) return token;
|
|
10
|
-
if (options.account?.encryptOAuthTokens) return (0, require_crypto.crypto_exports.symmetricDecrypt)({
|
|
11
|
-
key: ctx.get("context").secret,
|
|
12
|
-
data: token
|
|
13
|
-
});
|
|
14
|
-
return token;
|
|
15
|
-
};
|
|
16
|
-
const setTokenUtil = (token, ctx, options) => {
|
|
17
|
-
if (options.account?.encryptOAuthTokens && token) return (0, require_crypto.crypto_exports.symmetricEncrypt)({
|
|
18
|
-
key: ctx.get("context").secret,
|
|
19
|
-
data: token
|
|
20
|
-
});
|
|
21
|
-
return token;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
//#endregion
|
|
25
|
-
//#region src/oauth2/link-account.ts
|
|
26
|
-
const handleOAuthUserInfo = async (ctx, { userInfo, account, callbackURL, disableSignUp, overrideUserInfo }, options) => {
|
|
27
|
-
const context = ctx.get("context");
|
|
28
|
-
const redirectOnError = (reason) => {
|
|
29
|
-
const errorURL = options.onAPIError?.errorURL ?? `${context.baseURL}/error`;
|
|
30
|
-
return {
|
|
31
|
-
type: "redirect",
|
|
32
|
-
response: ctx.redirect(`${errorURL}?error=${reason}`, 302)
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
const dbUser = await context.internalAdapter.findOAuthUser(userInfo.email.toLowerCase(), account.accountId, account.providerId).catch((e) => {
|
|
36
|
-
__faire_auth_core_env.logger.error("Better auth was unable to query your database.\nError: ", e);
|
|
37
|
-
return "error";
|
|
38
|
-
});
|
|
39
|
-
if (dbUser === "error") return redirectOnError("internal_server_error");
|
|
40
|
-
let user = dbUser?.user ?? null;
|
|
41
|
-
const isRegister = user == null;
|
|
42
|
-
if (dbUser) {
|
|
43
|
-
const hasBeenLinked = dbUser.accounts.find((a) => a.providerId === account.providerId && a.accountId === account.accountId);
|
|
44
|
-
if (!hasBeenLinked) {
|
|
45
|
-
if (!(options.account?.accountLinking?.trustedProviders)?.includes(account.providerId) && !userInfo.emailVerified || options.account?.accountLinking?.enabled === false) {
|
|
46
|
-
if ((0, __faire_auth_core_env.isDevelopment)()) __faire_auth_core_env.logger.warn(`User already exist but account isn't linked to ${account.providerId}. To read more about how account linking works in Faire Auth see https://www.faire-auth.com/docs/concepts/users-accounts#account-linking.`);
|
|
47
|
-
return {
|
|
48
|
-
type: "error",
|
|
49
|
-
reason: "account_not_linked"
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
try {
|
|
53
|
-
await context.internalAdapter.linkAccount({
|
|
54
|
-
providerId: account.providerId,
|
|
55
|
-
accountId: userInfo.id.toString(),
|
|
56
|
-
userId: dbUser.user.id,
|
|
57
|
-
accessToken: await setTokenUtil(account.accessToken, ctx, options),
|
|
58
|
-
refreshToken: await setTokenUtil(account.refreshToken, ctx, options),
|
|
59
|
-
idToken: account.idToken,
|
|
60
|
-
accessTokenExpiresAt: account.accessTokenExpiresAt,
|
|
61
|
-
refreshTokenExpiresAt: account.refreshTokenExpiresAt,
|
|
62
|
-
scope: account.scope
|
|
63
|
-
});
|
|
64
|
-
} catch (e) {
|
|
65
|
-
__faire_auth_core_env.logger.error("Unable to link account", e);
|
|
66
|
-
return {
|
|
67
|
-
type: "error",
|
|
68
|
-
reason: "unable_to_link_account"
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
if (userInfo.emailVerified && !dbUser.user.emailVerified && userInfo.email.toLowerCase() === dbUser.user.email) await context.internalAdapter.updateUser(dbUser.user.id, { emailVerified: true });
|
|
72
|
-
} else {
|
|
73
|
-
if (options.account?.updateAccountOnSignIn !== false) {
|
|
74
|
-
const updateData = Object.fromEntries(Object.entries({
|
|
75
|
-
idToken: account.idToken,
|
|
76
|
-
accessToken: await setTokenUtil(account.accessToken, ctx, options),
|
|
77
|
-
refreshToken: await setTokenUtil(account.refreshToken, ctx, options),
|
|
78
|
-
accessTokenExpiresAt: account.accessTokenExpiresAt,
|
|
79
|
-
refreshTokenExpiresAt: account.refreshTokenExpiresAt,
|
|
80
|
-
scope: account.scope
|
|
81
|
-
}).filter(([, value]) => value !== void 0 && value !== ""));
|
|
82
|
-
if (Object.keys(updateData).length > 0) await context.internalAdapter.updateAccount(hasBeenLinked.id, updateData);
|
|
83
|
-
}
|
|
84
|
-
if (userInfo.emailVerified && !dbUser.user.emailVerified && userInfo.email.toLowerCase() === dbUser.user.email) await context.internalAdapter.updateUser(dbUser.user.id, { emailVerified: true });
|
|
85
|
-
}
|
|
86
|
-
if (overrideUserInfo === true) {
|
|
87
|
-
const { id: _,...restUserInfo } = userInfo;
|
|
88
|
-
await context.internalAdapter.updateUser(dbUser.user.id, {
|
|
89
|
-
...restUserInfo,
|
|
90
|
-
email: userInfo.email.toLowerCase(),
|
|
91
|
-
emailVerified: userInfo.email.toLowerCase() === dbUser.user.email ? dbUser.user.emailVerified || userInfo.emailVerified : userInfo.emailVerified
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
} else {
|
|
95
|
-
if (disableSignUp === true) return {
|
|
96
|
-
type: "error",
|
|
97
|
-
reason: "signup_disabled",
|
|
98
|
-
isRegister: false
|
|
99
|
-
};
|
|
100
|
-
try {
|
|
101
|
-
const { id: _,...restUserInfo } = userInfo;
|
|
102
|
-
user = await context.internalAdapter.createOAuthUser({
|
|
103
|
-
...restUserInfo,
|
|
104
|
-
email: userInfo.email.toLowerCase()
|
|
105
|
-
}, {
|
|
106
|
-
accessToken: await setTokenUtil(account.accessToken, ctx, options),
|
|
107
|
-
refreshToken: await setTokenUtil(account.refreshToken, ctx, options),
|
|
108
|
-
idToken: account.idToken,
|
|
109
|
-
accessTokenExpiresAt: account.accessTokenExpiresAt,
|
|
110
|
-
refreshTokenExpiresAt: account.refreshTokenExpiresAt,
|
|
111
|
-
scope: account.scope,
|
|
112
|
-
providerId: account.providerId,
|
|
113
|
-
accountId: userInfo.id.toString()
|
|
114
|
-
}).then((res) => res.user);
|
|
115
|
-
if (!userInfo.emailVerified && user && options.emailVerification?.sendOnSignUp === true) {
|
|
116
|
-
const token = await require_email_verification.createEmailVerificationToken(context.secret, user.email, void 0, options.emailVerification.expiresIn);
|
|
117
|
-
const url = `${context.baseURL}/verify-email?token=${token}${callbackURL ? `&callbackURL=${callbackURL}` : ""}`;
|
|
118
|
-
await options.emailVerification.sendVerificationEmail?.({
|
|
119
|
-
user,
|
|
120
|
-
url,
|
|
121
|
-
token
|
|
122
|
-
}, ctx);
|
|
123
|
-
}
|
|
124
|
-
} catch (e) {
|
|
125
|
-
__faire_auth_core_env.logger.error(e instanceof Error ? e.message : String(e), e);
|
|
126
|
-
if (e instanceof __faire_auth_core_error.APIError) return {
|
|
127
|
-
type: "error",
|
|
128
|
-
reason: e.message,
|
|
129
|
-
isRegister: false
|
|
130
|
-
};
|
|
131
|
-
return {
|
|
132
|
-
type: "error",
|
|
133
|
-
reason: "unable_to_create_user",
|
|
134
|
-
isRegister: false
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
if (!user) return {
|
|
139
|
-
type: "error",
|
|
140
|
-
reason: "unable_to_create_user",
|
|
141
|
-
isRegister: false
|
|
142
|
-
};
|
|
143
|
-
const session = await context.internalAdapter.createSession(user.id);
|
|
144
|
-
if (!session) return {
|
|
145
|
-
type: "error",
|
|
146
|
-
reason: "unable_to_create_session",
|
|
147
|
-
isRegister: false
|
|
148
|
-
};
|
|
149
|
-
return {
|
|
150
|
-
type: "success",
|
|
151
|
-
data: {
|
|
152
|
-
session,
|
|
153
|
-
user
|
|
154
|
-
},
|
|
155
|
-
isRegister
|
|
156
|
-
};
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
//#endregion
|
|
160
|
-
Object.defineProperty(exports, 'decryptOAuthToken', {
|
|
161
|
-
enumerable: true,
|
|
162
|
-
get: function () {
|
|
163
|
-
return decryptOAuthToken;
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
Object.defineProperty(exports, 'handleOAuthUserInfo', {
|
|
167
|
-
enumerable: true,
|
|
168
|
-
get: function () {
|
|
169
|
-
return handleOAuthUserInfo;
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
Object.defineProperty(exports, 'setTokenUtil', {
|
|
173
|
-
enumerable: true,
|
|
174
|
-
get: function () {
|
|
175
|
-
return setTokenUtil;
|
|
176
|
-
}
|
|
177
|
-
});
|
package/dist/oauth2-C56wz-n9.mjs
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import { n as crypto_exports } from "./crypto-DH2Aa7jN.mjs";
|
|
2
|
-
import { t as createEmailVerificationToken } from "./email-verification-C_lBu_JY.mjs";
|
|
3
|
-
import { isDevelopment, logger } from "@faire-auth/core/env";
|
|
4
|
-
import { APIError } from "@faire-auth/core/error";
|
|
5
|
-
|
|
6
|
-
//#region src/oauth2/utils.ts
|
|
7
|
-
const decryptOAuthToken = (token, ctx, options) => {
|
|
8
|
-
if (!token) return token;
|
|
9
|
-
if (options.account?.encryptOAuthTokens) return (0, crypto_exports.symmetricDecrypt)({
|
|
10
|
-
key: ctx.get("context").secret,
|
|
11
|
-
data: token
|
|
12
|
-
});
|
|
13
|
-
return token;
|
|
14
|
-
};
|
|
15
|
-
const setTokenUtil = (token, ctx, options) => {
|
|
16
|
-
if (options.account?.encryptOAuthTokens && token) return (0, crypto_exports.symmetricEncrypt)({
|
|
17
|
-
key: ctx.get("context").secret,
|
|
18
|
-
data: token
|
|
19
|
-
});
|
|
20
|
-
return token;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
//#region src/oauth2/link-account.ts
|
|
25
|
-
const handleOAuthUserInfo = async (ctx, { userInfo, account, callbackURL, disableSignUp, overrideUserInfo }, options) => {
|
|
26
|
-
const context = ctx.get("context");
|
|
27
|
-
const redirectOnError = (reason) => {
|
|
28
|
-
const errorURL = options.onAPIError?.errorURL ?? `${context.baseURL}/error`;
|
|
29
|
-
return {
|
|
30
|
-
type: "redirect",
|
|
31
|
-
response: ctx.redirect(`${errorURL}?error=${reason}`, 302)
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
const dbUser = await context.internalAdapter.findOAuthUser(userInfo.email.toLowerCase(), account.accountId, account.providerId).catch((e) => {
|
|
35
|
-
logger.error("Better auth was unable to query your database.\nError: ", e);
|
|
36
|
-
return "error";
|
|
37
|
-
});
|
|
38
|
-
if (dbUser === "error") return redirectOnError("internal_server_error");
|
|
39
|
-
let user = dbUser?.user ?? null;
|
|
40
|
-
const isRegister = user == null;
|
|
41
|
-
if (dbUser) {
|
|
42
|
-
const hasBeenLinked = dbUser.accounts.find((a) => a.providerId === account.providerId && a.accountId === account.accountId);
|
|
43
|
-
if (!hasBeenLinked) {
|
|
44
|
-
if (!(options.account?.accountLinking?.trustedProviders)?.includes(account.providerId) && !userInfo.emailVerified || options.account?.accountLinking?.enabled === false) {
|
|
45
|
-
if (isDevelopment()) logger.warn(`User already exist but account isn't linked to ${account.providerId}. To read more about how account linking works in Faire Auth see https://www.faire-auth.com/docs/concepts/users-accounts#account-linking.`);
|
|
46
|
-
return {
|
|
47
|
-
type: "error",
|
|
48
|
-
reason: "account_not_linked"
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
try {
|
|
52
|
-
await context.internalAdapter.linkAccount({
|
|
53
|
-
providerId: account.providerId,
|
|
54
|
-
accountId: userInfo.id.toString(),
|
|
55
|
-
userId: dbUser.user.id,
|
|
56
|
-
accessToken: await setTokenUtil(account.accessToken, ctx, options),
|
|
57
|
-
refreshToken: await setTokenUtil(account.refreshToken, ctx, options),
|
|
58
|
-
idToken: account.idToken,
|
|
59
|
-
accessTokenExpiresAt: account.accessTokenExpiresAt,
|
|
60
|
-
refreshTokenExpiresAt: account.refreshTokenExpiresAt,
|
|
61
|
-
scope: account.scope
|
|
62
|
-
});
|
|
63
|
-
} catch (e) {
|
|
64
|
-
logger.error("Unable to link account", e);
|
|
65
|
-
return {
|
|
66
|
-
type: "error",
|
|
67
|
-
reason: "unable_to_link_account"
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
if (userInfo.emailVerified && !dbUser.user.emailVerified && userInfo.email.toLowerCase() === dbUser.user.email) await context.internalAdapter.updateUser(dbUser.user.id, { emailVerified: true });
|
|
71
|
-
} else {
|
|
72
|
-
if (options.account?.updateAccountOnSignIn !== false) {
|
|
73
|
-
const updateData = Object.fromEntries(Object.entries({
|
|
74
|
-
idToken: account.idToken,
|
|
75
|
-
accessToken: await setTokenUtil(account.accessToken, ctx, options),
|
|
76
|
-
refreshToken: await setTokenUtil(account.refreshToken, ctx, options),
|
|
77
|
-
accessTokenExpiresAt: account.accessTokenExpiresAt,
|
|
78
|
-
refreshTokenExpiresAt: account.refreshTokenExpiresAt,
|
|
79
|
-
scope: account.scope
|
|
80
|
-
}).filter(([, value]) => value !== void 0 && value !== ""));
|
|
81
|
-
if (Object.keys(updateData).length > 0) await context.internalAdapter.updateAccount(hasBeenLinked.id, updateData);
|
|
82
|
-
}
|
|
83
|
-
if (userInfo.emailVerified && !dbUser.user.emailVerified && userInfo.email.toLowerCase() === dbUser.user.email) await context.internalAdapter.updateUser(dbUser.user.id, { emailVerified: true });
|
|
84
|
-
}
|
|
85
|
-
if (overrideUserInfo === true) {
|
|
86
|
-
const { id: _,...restUserInfo } = userInfo;
|
|
87
|
-
await context.internalAdapter.updateUser(dbUser.user.id, {
|
|
88
|
-
...restUserInfo,
|
|
89
|
-
email: userInfo.email.toLowerCase(),
|
|
90
|
-
emailVerified: userInfo.email.toLowerCase() === dbUser.user.email ? dbUser.user.emailVerified || userInfo.emailVerified : userInfo.emailVerified
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
} else {
|
|
94
|
-
if (disableSignUp === true) return {
|
|
95
|
-
type: "error",
|
|
96
|
-
reason: "signup_disabled",
|
|
97
|
-
isRegister: false
|
|
98
|
-
};
|
|
99
|
-
try {
|
|
100
|
-
const { id: _,...restUserInfo } = userInfo;
|
|
101
|
-
user = await context.internalAdapter.createOAuthUser({
|
|
102
|
-
...restUserInfo,
|
|
103
|
-
email: userInfo.email.toLowerCase()
|
|
104
|
-
}, {
|
|
105
|
-
accessToken: await setTokenUtil(account.accessToken, ctx, options),
|
|
106
|
-
refreshToken: await setTokenUtil(account.refreshToken, ctx, options),
|
|
107
|
-
idToken: account.idToken,
|
|
108
|
-
accessTokenExpiresAt: account.accessTokenExpiresAt,
|
|
109
|
-
refreshTokenExpiresAt: account.refreshTokenExpiresAt,
|
|
110
|
-
scope: account.scope,
|
|
111
|
-
providerId: account.providerId,
|
|
112
|
-
accountId: userInfo.id.toString()
|
|
113
|
-
}).then((res) => res.user);
|
|
114
|
-
if (!userInfo.emailVerified && user && options.emailVerification?.sendOnSignUp === true) {
|
|
115
|
-
const token = await createEmailVerificationToken(context.secret, user.email, void 0, options.emailVerification.expiresIn);
|
|
116
|
-
const url = `${context.baseURL}/verify-email?token=${token}${callbackURL ? `&callbackURL=${callbackURL}` : ""}`;
|
|
117
|
-
await options.emailVerification.sendVerificationEmail?.({
|
|
118
|
-
user,
|
|
119
|
-
url,
|
|
120
|
-
token
|
|
121
|
-
}, ctx);
|
|
122
|
-
}
|
|
123
|
-
} catch (e) {
|
|
124
|
-
logger.error(e instanceof Error ? e.message : String(e), e);
|
|
125
|
-
if (e instanceof APIError) return {
|
|
126
|
-
type: "error",
|
|
127
|
-
reason: e.message,
|
|
128
|
-
isRegister: false
|
|
129
|
-
};
|
|
130
|
-
return {
|
|
131
|
-
type: "error",
|
|
132
|
-
reason: "unable_to_create_user",
|
|
133
|
-
isRegister: false
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
if (!user) return {
|
|
138
|
-
type: "error",
|
|
139
|
-
reason: "unable_to_create_user",
|
|
140
|
-
isRegister: false
|
|
141
|
-
};
|
|
142
|
-
const session = await context.internalAdapter.createSession(user.id);
|
|
143
|
-
if (!session) return {
|
|
144
|
-
type: "error",
|
|
145
|
-
reason: "unable_to_create_session",
|
|
146
|
-
isRegister: false
|
|
147
|
-
};
|
|
148
|
-
return {
|
|
149
|
-
type: "success",
|
|
150
|
-
data: {
|
|
151
|
-
session,
|
|
152
|
-
user
|
|
153
|
-
},
|
|
154
|
-
isRegister
|
|
155
|
-
};
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
//#endregion
|
|
159
|
-
export { decryptOAuthToken as n, setTokenUtil as r, handleOAuthUserInfo as t };
|