@riffdb/better-auth 0.0.0-stage → 0.2.1
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/DESIGN.md +273 -0
- package/LICENSE-APACHE +201 -0
- package/LICENSE-MIT +27 -0
- package/README.md +323 -2
- package/dist/adapter.d.ts +34 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +1600 -0
- package/dist/adapter.js.map +1 -0
- package/dist/generated/client.d.ts +2166 -0
- package/dist/generated/client.d.ts.map +1 -0
- package/dist/generated/client.js +2454 -0
- package/dist/generated/client.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin-dispatch.d.ts +37 -0
- package/dist/plugin-dispatch.d.ts.map +1 -0
- package/dist/plugin-dispatch.js +293 -0
- package/dist/plugin-dispatch.js.map +1 -0
- package/dist/profile-contract.d.ts +63 -0
- package/dist/profile-contract.d.ts.map +1 -0
- package/dist/profile-contract.js +543 -0
- package/dist/profile-contract.js.map +1 -0
- package/dist/profile-plan.d.ts +69 -0
- package/dist/profile-plan.d.ts.map +1 -0
- package/dist/profile-plan.js +180 -0
- package/dist/profile-plan.js.map +1 -0
- package/dist/profile.d.ts +48 -0
- package/dist/profile.d.ts.map +1 -0
- package/dist/profile.js +132 -0
- package/dist/profile.js.map +1 -0
- package/dist/profiles/custom-fields/profile.d.ts +3 -0
- package/dist/profiles/custom-fields/profile.d.ts.map +1 -0
- package/dist/profiles/custom-fields/profile.js +475 -0
- package/dist/profiles/custom-fields/profile.js.map +1 -0
- package/dist/profiles/custom-fields/src/generated/client.d.ts +2710 -0
- package/dist/profiles/custom-fields/src/generated/client.d.ts.map +1 -0
- package/dist/profiles/custom-fields/src/generated/client.js +2663 -0
- package/dist/profiles/custom-fields/src/generated/client.js.map +1 -0
- package/dist/profiles/runtime/profile.d.ts +3 -0
- package/dist/profiles/runtime/profile.d.ts.map +1 -0
- package/dist/profiles/runtime/profile.js +1065 -0
- package/dist/profiles/runtime/profile.js.map +1 -0
- package/dist/profiles/runtime/src/generated/client.d.ts +4274 -0
- package/dist/profiles/runtime/src/generated/client.d.ts.map +1 -0
- package/dist/profiles/runtime/src/generated/client.js +4607 -0
- package/dist/profiles/runtime/src/generated/client.js.map +1 -0
- package/dist/runtime-materialize.d.ts +10 -0
- package/dist/runtime-materialize.d.ts.map +1 -0
- package/dist/runtime-materialize.js +344 -0
- package/dist/runtime-materialize.js.map +1 -0
- package/dist/runtime-profile.d.ts +34 -0
- package/dist/runtime-profile.d.ts.map +1 -0
- package/dist/runtime-profile.js +203 -0
- package/dist/runtime-profile.js.map +1 -0
- package/dist/testing.d.ts +11 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +12 -0
- package/dist/testing.js.map +1 -0
- package/generated/go/client.go +2250 -0
- package/generated/mcp/tools.json +13922 -0
- package/generated/python/client.py +4454 -0
- package/generated/riffdb.application.exact.json +1 -0
- package/generated/riffdb.contract.bundle +0 -0
- package/generated/rust/client.rs +6524 -0
- package/package.json +83 -4
- package/profiles/custom-fields/generated/go/client.go +2578 -0
- package/profiles/custom-fields/generated/mcp/tools.json +15998 -0
- package/profiles/custom-fields/generated/python/client.py +5141 -0
- package/profiles/custom-fields/generated/riffdb.application.exact.json +1 -0
- package/profiles/custom-fields/generated/riffdb.contract.bundle +0 -0
- package/profiles/custom-fields/generated/rust/client.rs +7980 -0
- package/profiles/custom-fields/profile.ts +474 -0
- package/profiles/custom-fields/riffdb/contract.riff +568 -0
- package/profiles/custom-fields/riffdb/queries/admin_users_all_email_asc.riffq +24 -0
- package/profiles/custom-fields/riffdb/queries/admin_users_contains_asc.riffq +24 -0
- package/profiles/custom-fields/riffdb/queries/admin_users_contains_desc.riffq +24 -0
- package/profiles/custom-fields/riffdb/queries/admin_users_email_contains_created_desc.riffq +24 -0
- package/profiles/custom-fields/riffdb/queries/admin_users_email_contains_image_asc.riffq +24 -0
- package/profiles/custom-fields/riffdb/queries/admin_users_ends_with_asc.riffq +24 -0
- package/profiles/custom-fields/riffdb/queries/admin_users_ends_with_desc.riffq +24 -0
- package/profiles/custom-fields/riffdb/queries/admin_users_starts_with_asc.riffq +24 -0
- package/profiles/custom-fields/riffdb/queries/admin_users_starts_with_desc.riffq +24 -0
- package/profiles/custom-fields/riffdb/queries/find_account_by_id.riffq +24 -0
- package/profiles/custom-fields/riffdb/queries/find_account_by_provider.riffq +26 -0
- package/profiles/custom-fields/riffdb/queries/find_accounts_by_user_id.riffq +25 -0
- package/profiles/custom-fields/riffdb/queries/find_accounts_by_user_provider.riffq +27 -0
- package/profiles/custom-fields/riffdb/queries/find_active_sessions_by_user_id.riffq +23 -0
- package/profiles/custom-fields/riffdb/queries/find_credential_account.riffq +25 -0
- package/profiles/custom-fields/riffdb/queries/find_expired_verification_ids.riffq +17 -0
- package/profiles/custom-fields/riffdb/queries/find_latest_verification.riffq +20 -0
- package/profiles/custom-fields/riffdb/queries/find_session_by_id.riffq +20 -0
- package/profiles/custom-fields/riffdb/queries/find_session_by_token.riffq +20 -0
- package/profiles/custom-fields/riffdb/queries/find_sessions_by_token_set.riffq +20 -0
- package/profiles/custom-fields/riffdb/queries/find_sessions_by_user_id.riffq +21 -0
- package/profiles/custom-fields/riffdb/queries/find_user_by_email.riffq +16 -0
- package/profiles/custom-fields/riffdb/queries/find_user_by_id.riffq +15 -0
- package/profiles/custom-fields/riffdb/queries/find_verification_by_id.riffq +19 -0
- package/profiles/custom-fields/riffdb/queries/find_verifications_by_identifier.riffq +21 -0
- package/profiles/custom-fields/riffdb/queries/profile_account_with_user_by_provider.riffq +31 -0
- package/profiles/custom-fields/riffdb/queries/profile_session_with_user_by_id.riffq +14 -0
- package/profiles/custom-fields/riffdb/queries/profile_session_with_user_by_token.riffq +14 -0
- package/profiles/custom-fields/riffdb/queries/profile_sessions_with_users_by_token_set.riffq +25 -0
- package/profiles/custom-fields/riffdb/queries/profile_user_with_accounts_by_email.riffq +19 -0
- package/profiles/custom-fields/riffdb/queries/profile_user_with_accounts_by_id.riffq +19 -0
- package/profiles/custom-fields/riffdb.application.json +217 -0
- package/profiles/custom-fields/riffdb.application.lock.json +1 -0
- package/profiles/custom-fields/riffdb.toml +3 -0
- package/profiles/custom-fields/src/generated/client.ts +3096 -0
- package/profiles/organization-security/materialization.json +51 -0
- package/profiles/organization-security/riffdb/contract.riff +778 -0
- package/profiles/organization-security/riffdb/queries/find_account_by_id.riffq +18 -0
- package/profiles/organization-security/riffdb/queries/find_invitation_by_email.riffq +17 -0
- package/profiles/organization-security/riffdb/queries/find_invitation_by_id.riffq +18 -0
- package/profiles/organization-security/riffdb/queries/find_invitation_by_organization_id.riffq +17 -0
- package/profiles/organization-security/riffdb/queries/find_member_by_id.riffq +18 -0
- package/profiles/organization-security/riffdb/queries/find_member_by_user_id.riffq +17 -0
- package/profiles/organization-security/riffdb/queries/find_organization_by_id.riffq +16 -0
- package/profiles/organization-security/riffdb/queries/find_organization_by_slug.riffq +16 -0
- package/profiles/organization-security/riffdb/queries/find_session_by_id.riffq +18 -0
- package/profiles/organization-security/riffdb/queries/find_session_by_token.riffq +16 -0
- package/profiles/organization-security/riffdb/queries/find_team_by_id.riffq +18 -0
- package/profiles/organization-security/riffdb/queries/find_team_member_by_id.riffq +18 -0
- package/profiles/organization-security/riffdb/queries/find_team_member_by_membership_key.riffq +16 -0
- package/profiles/organization-security/riffdb/queries/find_team_member_by_team_id.riffq +17 -0
- package/profiles/organization-security/riffdb/queries/find_two_factor_by_id.riffq +18 -0
- package/profiles/organization-security/riffdb/queries/find_two_factor_by_secret.riffq +17 -0
- package/profiles/organization-security/riffdb/queries/find_user_by_email.riffq +16 -0
- package/profiles/organization-security/riffdb/queries/find_user_by_id.riffq +16 -0
- package/profiles/organization-security/riffdb/queries/find_verification_by_id.riffq +16 -0
- package/profiles/organization-security/riffdb/queries/find_verification_by_identifier.riffq +17 -0
- package/profiles/organization-security/riffdb.application.json +172 -0
- package/profiles/organization-security/riffdb.toml +7 -0
- package/profiles/organization-security.profile.json +980 -0
- package/profiles/runtime/generated/go/client.go +4511 -0
- package/profiles/runtime/generated/mcp/tools.json +30004 -0
- package/profiles/runtime/generated/python/client.py +9337 -0
- package/profiles/runtime/generated/riffdb.application.exact.json +1 -0
- package/profiles/runtime/generated/riffdb.contract.bundle +0 -0
- package/profiles/runtime/generated/rust/client.rs +13297 -0
- package/profiles/runtime/profile.ts +1064 -0
- package/profiles/runtime/riffdb/contract.riff +1053 -0
- package/profiles/runtime/riffdb/queries/admin_users_all_email_asc.riffq +24 -0
- package/profiles/runtime/riffdb/queries/admin_users_contains_asc.riffq +24 -0
- package/profiles/runtime/riffdb/queries/admin_users_contains_desc.riffq +24 -0
- package/profiles/runtime/riffdb/queries/admin_users_email_contains_created_desc.riffq +24 -0
- package/profiles/runtime/riffdb/queries/admin_users_email_contains_image_asc.riffq +24 -0
- package/profiles/runtime/riffdb/queries/admin_users_ends_with_asc.riffq +24 -0
- package/profiles/runtime/riffdb/queries/admin_users_ends_with_desc.riffq +24 -0
- package/profiles/runtime/riffdb/queries/admin_users_starts_with_asc.riffq +24 -0
- package/profiles/runtime/riffdb/queries/admin_users_starts_with_desc.riffq +24 -0
- package/profiles/runtime/riffdb/queries/find_account_by_id.riffq +24 -0
- package/profiles/runtime/riffdb/queries/find_account_by_provider.riffq +26 -0
- package/profiles/runtime/riffdb/queries/find_accounts_by_user_id.riffq +25 -0
- package/profiles/runtime/riffdb/queries/find_accounts_by_user_provider.riffq +27 -0
- package/profiles/runtime/riffdb/queries/find_active_sessions_by_user_id.riffq +23 -0
- package/profiles/runtime/riffdb/queries/find_credential_account.riffq +25 -0
- package/profiles/runtime/riffdb/queries/find_expired_verification_ids.riffq +17 -0
- package/profiles/runtime/riffdb/queries/find_latest_verification.riffq +20 -0
- package/profiles/runtime/riffdb/queries/find_session_by_id.riffq +20 -0
- package/profiles/runtime/riffdb/queries/find_session_by_token.riffq +20 -0
- package/profiles/runtime/riffdb/queries/find_sessions_by_token_set.riffq +20 -0
- package/profiles/runtime/riffdb/queries/find_sessions_by_user_id.riffq +21 -0
- package/profiles/runtime/riffdb/queries/find_user_by_email.riffq +16 -0
- package/profiles/runtime/riffdb/queries/find_user_by_id.riffq +15 -0
- package/profiles/runtime/riffdb/queries/find_verification_by_id.riffq +19 -0
- package/profiles/runtime/riffdb/queries/find_verifications_by_identifier.riffq +21 -0
- package/profiles/runtime/riffdb/queries/profile_account_with_user_by_provider.riffq +31 -0
- package/profiles/runtime/riffdb/queries/profile_invitation_by_email.riffq +17 -0
- package/profiles/runtime/riffdb/queries/profile_invitation_by_id.riffq +17 -0
- package/profiles/runtime/riffdb/queries/profile_invitation_by_organization_email_status.riffq +19 -0
- package/profiles/runtime/riffdb/queries/profile_invitation_by_organization_id.riffq +17 -0
- package/profiles/runtime/riffdb/queries/profile_invitation_by_organization_status.riffq +18 -0
- package/profiles/runtime/riffdb/queries/profile_member_by_id.riffq +27 -0
- package/profiles/runtime/riffdb/queries/profile_member_by_organization.riffq +20 -0
- package/profiles/runtime/riffdb/queries/profile_member_by_organization_created_at_asc.riffq +20 -0
- package/profiles/runtime/riffdb/queries/profile_member_by_organization_created_at_desc.riffq +20 -0
- package/profiles/runtime/riffdb/queries/profile_member_by_organization_role_asc.riffq +20 -0
- package/profiles/runtime/riffdb/queries/profile_member_by_organization_role_desc.riffq +20 -0
- package/profiles/runtime/riffdb/queries/profile_member_by_organization_user.riffq +28 -0
- package/profiles/runtime/riffdb/queries/profile_member_by_user.riffq +27 -0
- package/profiles/runtime/riffdb/queries/profile_organization_by_id.riffq +27 -0
- package/profiles/runtime/riffdb/queries/profile_organization_by_slug.riffq +27 -0
- package/profiles/runtime/riffdb/queries/profile_session_with_user_by_id.riffq +14 -0
- package/profiles/runtime/riffdb/queries/profile_session_with_user_by_token.riffq +14 -0
- package/profiles/runtime/riffdb/queries/profile_sessions_with_users_by_token_set.riffq +25 -0
- package/profiles/runtime/riffdb/queries/profile_two_factor_by_id.riffq +17 -0
- package/profiles/runtime/riffdb/queries/profile_two_factor_by_user.riffq +17 -0
- package/profiles/runtime/riffdb/queries/profile_user_with_accounts_by_email.riffq +19 -0
- package/profiles/runtime/riffdb/queries/profile_user_with_accounts_by_id.riffq +19 -0
- package/profiles/runtime/riffdb/queries/profile_users_by_id_set.riffq +8 -0
- package/profiles/runtime/riffdb.application.json +324 -0
- package/profiles/runtime/riffdb.application.lock.json +1 -0
- package/profiles/runtime/riffdb.toml +3 -0
- package/profiles/runtime/src/generated/client.ts +5186 -0
- package/riffdb/contract.riff +547 -0
- package/riffdb/queries/admin_users_all_email_asc.riffq +24 -0
- package/riffdb/queries/admin_users_contains_asc.riffq +24 -0
- package/riffdb/queries/admin_users_contains_desc.riffq +24 -0
- package/riffdb/queries/admin_users_email_contains_created_desc.riffq +24 -0
- package/riffdb/queries/admin_users_email_contains_image_asc.riffq +24 -0
- package/riffdb/queries/admin_users_ends_with_asc.riffq +24 -0
- package/riffdb/queries/admin_users_ends_with_desc.riffq +24 -0
- package/riffdb/queries/admin_users_starts_with_asc.riffq +24 -0
- package/riffdb/queries/admin_users_starts_with_desc.riffq +24 -0
- package/riffdb/queries/find_account_by_id.riffq +24 -0
- package/riffdb/queries/find_account_by_provider.riffq +26 -0
- package/riffdb/queries/find_accounts_by_user_id.riffq +25 -0
- package/riffdb/queries/find_accounts_by_user_provider.riffq +27 -0
- package/riffdb/queries/find_active_sessions_by_user_id.riffq +23 -0
- package/riffdb/queries/find_credential_account.riffq +25 -0
- package/riffdb/queries/find_expired_verification_ids.riffq +17 -0
- package/riffdb/queries/find_latest_verification.riffq +20 -0
- package/riffdb/queries/find_session_by_id.riffq +20 -0
- package/riffdb/queries/find_session_by_token.riffq +20 -0
- package/riffdb/queries/find_sessions_by_token_set.riffq +20 -0
- package/riffdb/queries/find_sessions_by_user_id.riffq +21 -0
- package/riffdb/queries/find_user_by_email.riffq +16 -0
- package/riffdb/queries/find_user_by_id.riffq +15 -0
- package/riffdb/queries/find_verification_by_id.riffq +19 -0
- package/riffdb/queries/find_verifications_by_identifier.riffq +21 -0
- package/riffdb.application.json +187 -0
- package/riffdb.application.lock.json +1 -0
- package/scripts/real-riffdb-runner.mjs +333 -0
- package/src/generated/client.ts +2746 -0
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
|
|
3
|
+
import { DriverApplicationTransport } from "@riffdb/client";
|
|
4
|
+
import { betterAuth } from "better-auth";
|
|
5
|
+
|
|
6
|
+
import { riffdbAdapter } from "../dist/index.js";
|
|
7
|
+
|
|
8
|
+
const ORGANIZATION_ID = "018f5f7e-7b0c-7d9a-8f14-77f42f53c851";
|
|
9
|
+
const arguments_ = process.argv.slice(2);
|
|
10
|
+
if (arguments_.length !== 10) {
|
|
11
|
+
throw new Error(
|
|
12
|
+
"usage: real-riffdb-runner SOCKET MANIFEST_HASH CATALOG_HASH DATABASE ROLE ROLE_HASH REMOTE_HASH LINEAGE VERSION BUNDLE_HASH",
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
const [
|
|
16
|
+
socketPath,
|
|
17
|
+
applicationManifestHash,
|
|
18
|
+
operationCatalogHash,
|
|
19
|
+
database,
|
|
20
|
+
role,
|
|
21
|
+
roleDefinitionHash,
|
|
22
|
+
remoteIdentityHash,
|
|
23
|
+
contractLineage,
|
|
24
|
+
contractVersion,
|
|
25
|
+
contractBundleHash,
|
|
26
|
+
] = arguments_;
|
|
27
|
+
|
|
28
|
+
const driver = await DriverApplicationTransport.connect({
|
|
29
|
+
socketPath,
|
|
30
|
+
identity: {
|
|
31
|
+
applicationManifestHash,
|
|
32
|
+
operationCatalogHash,
|
|
33
|
+
database,
|
|
34
|
+
role,
|
|
35
|
+
roleDefinitionHash,
|
|
36
|
+
remoteIdentityHash,
|
|
37
|
+
contractLineage,
|
|
38
|
+
contractVersion: BigInt(contractVersion),
|
|
39
|
+
contractBundleHash,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
let resetToken = "";
|
|
45
|
+
const databaseAdapter = riffdbAdapter({ driver, organizationId: ORGANIZATION_ID });
|
|
46
|
+
const authOptions = {
|
|
47
|
+
database: databaseAdapter,
|
|
48
|
+
baseURL: "http://localhost:3000",
|
|
49
|
+
secret: "riffdb-better-auth-development-only-secret-value",
|
|
50
|
+
advanced: { database: { generateId: "uuid" } },
|
|
51
|
+
emailAndPassword: {
|
|
52
|
+
enabled: true,
|
|
53
|
+
password: {
|
|
54
|
+
hash: async (password) => password,
|
|
55
|
+
verify: async ({ hash, password }) => hash === password,
|
|
56
|
+
},
|
|
57
|
+
async sendResetPassword({ token }) {
|
|
58
|
+
resetToken = token;
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
const auth = betterAuth(authOptions);
|
|
63
|
+
|
|
64
|
+
const email = `real-${crypto.randomUUID()}@example.test`;
|
|
65
|
+
const originalPassword = `${crypto.randomUUID()}-old`;
|
|
66
|
+
const newPassword = `${crypto.randomUUID()}-new`;
|
|
67
|
+
const signup = await auth.api.signUpEmail({
|
|
68
|
+
body: { email, password: originalPassword, name: "RiffDB Loopback" },
|
|
69
|
+
});
|
|
70
|
+
assert.equal(signup.user.email, email);
|
|
71
|
+
assert.match(signup.user.id, /^[0-9a-f-]{36}$/iu);
|
|
72
|
+
|
|
73
|
+
const signin = await auth.api.signInEmail({
|
|
74
|
+
body: { email, password: originalPassword },
|
|
75
|
+
});
|
|
76
|
+
assert.equal(signin.user.id, signup.user.id);
|
|
77
|
+
|
|
78
|
+
await auth.api.requestPasswordReset({
|
|
79
|
+
body: { email, redirectTo: "http://localhost:3000/reset-password" },
|
|
80
|
+
});
|
|
81
|
+
assert.ok(resetToken.length > 10);
|
|
82
|
+
const reset = await auth.api.resetPassword({
|
|
83
|
+
body: { token: resetToken, newPassword },
|
|
84
|
+
});
|
|
85
|
+
assert.equal(reset.status, true);
|
|
86
|
+
|
|
87
|
+
const afterReset = await auth.api.signInEmail({
|
|
88
|
+
body: { email, password: newPassword },
|
|
89
|
+
});
|
|
90
|
+
assert.equal(afterReset.user.id, signup.user.id);
|
|
91
|
+
await assert.rejects(
|
|
92
|
+
auth.api.resetPassword({
|
|
93
|
+
body: { token: resetToken, newPassword: `${crypto.randomUUID()}-replay` },
|
|
94
|
+
}),
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
const directAdapter = databaseAdapter(authOptions);
|
|
98
|
+
const updatedAt = new Date();
|
|
99
|
+
assert.equal(
|
|
100
|
+
(
|
|
101
|
+
await directAdapter.update({
|
|
102
|
+
model: "user",
|
|
103
|
+
where: [{ field: "id", value: signup.user.id }],
|
|
104
|
+
update: { name: "RiffDB Updated", updatedAt },
|
|
105
|
+
})
|
|
106
|
+
)?.name,
|
|
107
|
+
"RiffDB Updated",
|
|
108
|
+
);
|
|
109
|
+
const sessions = await directAdapter.findMany({
|
|
110
|
+
model: "session",
|
|
111
|
+
where: [{ field: "userId", value: signup.user.id }],
|
|
112
|
+
});
|
|
113
|
+
assert.ok(sessions.length >= 1);
|
|
114
|
+
assert.equal(
|
|
115
|
+
(
|
|
116
|
+
await directAdapter.update({
|
|
117
|
+
model: "session",
|
|
118
|
+
where: [{ field: "token", value: sessions[0].token }],
|
|
119
|
+
update: { updatedAt: new Date() },
|
|
120
|
+
})
|
|
121
|
+
)?.id,
|
|
122
|
+
sessions[0].id,
|
|
123
|
+
);
|
|
124
|
+
const activeSessions = await directAdapter.findMany({
|
|
125
|
+
model: "session",
|
|
126
|
+
where: [
|
|
127
|
+
{ field: "userId", value: signup.user.id },
|
|
128
|
+
{ field: "expiresAt", value: new Date(), operator: "gt" },
|
|
129
|
+
],
|
|
130
|
+
});
|
|
131
|
+
assert.ok(activeSessions.length >= 1);
|
|
132
|
+
assert.equal(
|
|
133
|
+
(
|
|
134
|
+
await directAdapter.findMany({
|
|
135
|
+
model: "session",
|
|
136
|
+
where: [{ field: "token", value: [sessions[0].token], operator: "in" }],
|
|
137
|
+
})
|
|
138
|
+
)[0]?.id,
|
|
139
|
+
sessions[0].id,
|
|
140
|
+
);
|
|
141
|
+
assert.equal(
|
|
142
|
+
await directAdapter.deleteMany({
|
|
143
|
+
model: "session",
|
|
144
|
+
where: [{ field: "token", value: [sessions[0].token], operator: "in" }],
|
|
145
|
+
}),
|
|
146
|
+
1,
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
const verificationNow = new Date();
|
|
150
|
+
const expiredVerificationId = crypto.randomUUID();
|
|
151
|
+
const currentVerificationId = crypto.randomUUID();
|
|
152
|
+
const currentVerificationIdentifier = `real-verification:${crypto.randomUUID()}`;
|
|
153
|
+
await directAdapter.create({
|
|
154
|
+
model: "verification",
|
|
155
|
+
forceAllowId: true,
|
|
156
|
+
data: {
|
|
157
|
+
id: expiredVerificationId,
|
|
158
|
+
identifier: `expired:${crypto.randomUUID()}`,
|
|
159
|
+
value: "expired",
|
|
160
|
+
expiresAt: new Date(verificationNow.getTime() - 60_000),
|
|
161
|
+
createdAt: new Date(verificationNow.getTime() - 120_000),
|
|
162
|
+
updatedAt: new Date(verificationNow.getTime() - 120_000),
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
await directAdapter.create({
|
|
166
|
+
model: "verification",
|
|
167
|
+
forceAllowId: true,
|
|
168
|
+
data: {
|
|
169
|
+
id: currentVerificationId,
|
|
170
|
+
identifier: currentVerificationIdentifier,
|
|
171
|
+
value: "current",
|
|
172
|
+
expiresAt: new Date(verificationNow.getTime() + 60_000),
|
|
173
|
+
createdAt: verificationNow,
|
|
174
|
+
updatedAt: verificationNow,
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
assert.equal(
|
|
178
|
+
(
|
|
179
|
+
await directAdapter.update({
|
|
180
|
+
model: "verification",
|
|
181
|
+
where: [{ field: "identifier", value: currentVerificationIdentifier }],
|
|
182
|
+
update: { value: "updated" },
|
|
183
|
+
})
|
|
184
|
+
)?.value,
|
|
185
|
+
"updated",
|
|
186
|
+
);
|
|
187
|
+
assert.equal(
|
|
188
|
+
await directAdapter.deleteMany({
|
|
189
|
+
model: "verification",
|
|
190
|
+
where: [{ field: "expiresAt", value: verificationNow, operator: "lt" }],
|
|
191
|
+
}),
|
|
192
|
+
1,
|
|
193
|
+
);
|
|
194
|
+
await directAdapter.delete({
|
|
195
|
+
model: "verification",
|
|
196
|
+
where: [{ field: "identifier", value: currentVerificationIdentifier }],
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
const oauthUserId = crypto.randomUUID();
|
|
200
|
+
const oauthAccountId = crypto.randomUUID();
|
|
201
|
+
const oauthExternalId = `github-${crypto.randomUUID()}`;
|
|
202
|
+
const oauthNow = new Date();
|
|
203
|
+
await directAdapter.transaction(async (tx) => {
|
|
204
|
+
await tx.create({
|
|
205
|
+
model: "user",
|
|
206
|
+
forceAllowId: true,
|
|
207
|
+
data: {
|
|
208
|
+
id: oauthUserId,
|
|
209
|
+
name: "OAuth User",
|
|
210
|
+
email: `oauth-${crypto.randomUUID()}@example.test`,
|
|
211
|
+
emailVerified: true,
|
|
212
|
+
image: "oauth.png",
|
|
213
|
+
createdAt: oauthNow,
|
|
214
|
+
updatedAt: oauthNow,
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
await tx.create({
|
|
218
|
+
model: "account",
|
|
219
|
+
forceAllowId: true,
|
|
220
|
+
data: {
|
|
221
|
+
id: oauthAccountId,
|
|
222
|
+
userId: oauthUserId,
|
|
223
|
+
accountId: oauthExternalId,
|
|
224
|
+
providerId: "github",
|
|
225
|
+
accessToken: "oauth-access-token",
|
|
226
|
+
createdAt: oauthNow,
|
|
227
|
+
updatedAt: oauthNow,
|
|
228
|
+
},
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
assert.equal(
|
|
232
|
+
(
|
|
233
|
+
await directAdapter.findOne({
|
|
234
|
+
model: "user",
|
|
235
|
+
where: [{ field: "id", value: oauthUserId }],
|
|
236
|
+
})
|
|
237
|
+
)?.id,
|
|
238
|
+
oauthUserId,
|
|
239
|
+
);
|
|
240
|
+
const oauthAccountById = await directAdapter.findOne({
|
|
241
|
+
model: "account",
|
|
242
|
+
where: [{ field: "id", value: oauthAccountId }],
|
|
243
|
+
});
|
|
244
|
+
assert.equal(oauthAccountById?.id, oauthAccountId);
|
|
245
|
+
assert.equal(oauthAccountById?.accountId, oauthExternalId);
|
|
246
|
+
assert.equal(oauthAccountById?.providerId, "github");
|
|
247
|
+
assert.equal(
|
|
248
|
+
(
|
|
249
|
+
await directAdapter.findOne({
|
|
250
|
+
model: "account",
|
|
251
|
+
where: [
|
|
252
|
+
{ field: "accountId", value: oauthExternalId },
|
|
253
|
+
{ field: "providerId", value: "github" },
|
|
254
|
+
],
|
|
255
|
+
})
|
|
256
|
+
)?.id,
|
|
257
|
+
oauthAccountId,
|
|
258
|
+
);
|
|
259
|
+
assert.equal(
|
|
260
|
+
(
|
|
261
|
+
await directAdapter.update({
|
|
262
|
+
model: "account",
|
|
263
|
+
where: [{ field: "id", value: oauthAccountId }],
|
|
264
|
+
update: { accessToken: "oauth-access-token-2", updatedAt: new Date() },
|
|
265
|
+
})
|
|
266
|
+
)?.accessToken,
|
|
267
|
+
"oauth-access-token-2",
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
assert.equal(await directAdapter.count({ model: "user" }), 2);
|
|
271
|
+
assert.equal(
|
|
272
|
+
await directAdapter.count({
|
|
273
|
+
model: "user",
|
|
274
|
+
where: [{ field: "email", value: "@example.test", operator: "ends_with" }],
|
|
275
|
+
}),
|
|
276
|
+
2,
|
|
277
|
+
);
|
|
278
|
+
const usersByNullableImage = await directAdapter.findMany({
|
|
279
|
+
model: "user",
|
|
280
|
+
where: [{ field: "email", value: "example", operator: "contains" }],
|
|
281
|
+
limit: 2,
|
|
282
|
+
sortBy: { field: "image", direction: "asc" },
|
|
283
|
+
});
|
|
284
|
+
assert.deepEqual(
|
|
285
|
+
usersByNullableImage.map((record) => record.id),
|
|
286
|
+
[oauthUserId, signup.user.id],
|
|
287
|
+
);
|
|
288
|
+
assert.equal(
|
|
289
|
+
(
|
|
290
|
+
await directAdapter.findMany({
|
|
291
|
+
model: "user",
|
|
292
|
+
where: [{ field: "email", value: "@example.test", operator: "ends_with" }],
|
|
293
|
+
limit: 1,
|
|
294
|
+
offset: 1,
|
|
295
|
+
sortBy: { field: "email", direction: "desc" },
|
|
296
|
+
})
|
|
297
|
+
).length,
|
|
298
|
+
1,
|
|
299
|
+
);
|
|
300
|
+
await directAdapter.delete({
|
|
301
|
+
model: "user",
|
|
302
|
+
where: [{ field: "id", value: oauthUserId }],
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
assert.ok(
|
|
306
|
+
(await directAdapter.deleteMany({
|
|
307
|
+
model: "session",
|
|
308
|
+
where: [{ field: "userId", value: signup.user.id }],
|
|
309
|
+
})) >= 1,
|
|
310
|
+
);
|
|
311
|
+
assert.equal(
|
|
312
|
+
await directAdapter.deleteMany({
|
|
313
|
+
model: "account",
|
|
314
|
+
where: [{ field: "userId", value: signup.user.id }],
|
|
315
|
+
}),
|
|
316
|
+
1,
|
|
317
|
+
);
|
|
318
|
+
await directAdapter.delete({
|
|
319
|
+
model: "user",
|
|
320
|
+
where: [{ field: "id", value: signup.user.id }],
|
|
321
|
+
});
|
|
322
|
+
assert.equal(
|
|
323
|
+
await directAdapter.findOne({
|
|
324
|
+
model: "user",
|
|
325
|
+
where: [{ field: "id", value: signup.user.id }],
|
|
326
|
+
}),
|
|
327
|
+
null,
|
|
328
|
+
);
|
|
329
|
+
|
|
330
|
+
process.stdout.write("riffdb-better-auth-real-v1\tpassed\n");
|
|
331
|
+
} finally {
|
|
332
|
+
await driver.shutdown();
|
|
333
|
+
}
|