payload-auth 1.4.1 → 1.5.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/better-auth/adapter/transform/index.js +3 -3
- package/dist/better-auth/generated-types.d.ts +216 -0
- package/dist/better-auth/generated-types.d.ts.map +1 -0
- package/dist/better-auth/generated-types.js +4 -0
- package/dist/better-auth/plugin/constants.d.ts +145 -3
- package/dist/better-auth/plugin/constants.d.ts.map +1 -1
- package/dist/better-auth/plugin/constants.js +148 -6
- package/dist/better-auth/plugin/helpers/check-plugin-exists.d.ts +13 -0
- package/dist/better-auth/plugin/helpers/check-plugin-exists.d.ts.map +1 -0
- package/dist/better-auth/plugin/helpers/check-plugin-exists.js +14 -0
- package/dist/better-auth/plugin/helpers/get-better-auth-schema.d.ts +22 -0
- package/dist/better-auth/plugin/helpers/get-better-auth-schema.d.ts.map +1 -0
- package/dist/better-auth/plugin/helpers/get-better-auth-schema.js +50 -0
- package/dist/better-auth/plugin/helpers/get-collection-schema-map.d.ts +16 -0
- package/dist/better-auth/plugin/helpers/get-collection-schema-map.d.ts.map +1 -0
- package/dist/better-auth/plugin/helpers/get-collection-schema-map.js +108 -0
- package/dist/better-auth/plugin/helpers/get-collection-slug.d.ts +6 -0
- package/dist/better-auth/plugin/helpers/get-collection-slug.d.ts.map +1 -0
- package/dist/better-auth/plugin/helpers/get-collection-slug.js +20 -0
- package/dist/better-auth/plugin/helpers/get-collection.d.ts +41 -0
- package/dist/better-auth/plugin/helpers/get-collection.d.ts.map +1 -0
- package/dist/better-auth/plugin/helpers/get-collection.js +62 -0
- package/dist/better-auth/plugin/helpers/prepare-session-data.d.ts +8 -16
- package/dist/better-auth/plugin/helpers/prepare-session-data.d.ts.map +1 -1
- package/dist/better-auth/plugin/helpers/prepare-session-data.js +9 -20
- package/dist/better-auth/plugin/index.d.ts +3 -3
- package/dist/better-auth/plugin/index.d.ts.map +1 -1
- package/dist/better-auth/plugin/index.js +31 -40
- package/dist/better-auth/plugin/lib/build-collections/accounts/hooks/sync-password-to-user.d.ts +2 -6
- package/dist/better-auth/plugin/lib/build-collections/accounts/hooks/sync-password-to-user.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/build-collections/accounts/hooks/sync-password-to-user.js +22 -7
- package/dist/better-auth/plugin/lib/build-collections/accounts/index.d.ts +3 -6
- package/dist/better-auth/plugin/lib/build-collections/accounts/index.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/build-collections/accounts/index.js +96 -102
- package/dist/better-auth/plugin/lib/build-collections/admin-invitations/index.d.ts +2 -2
- package/dist/better-auth/plugin/lib/build-collections/admin-invitations/index.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/build-collections/admin-invitations/index.js +6 -5
- package/dist/better-auth/plugin/lib/build-collections/api-keys.d.ts +3 -5
- package/dist/better-auth/plugin/lib/build-collections/api-keys.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/build-collections/api-keys.js +97 -113
- package/dist/better-auth/plugin/lib/build-collections/index.d.ts +6 -6
- package/dist/better-auth/plugin/lib/build-collections/index.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/build-collections/index.js +68 -84
- package/dist/better-auth/plugin/lib/build-collections/invitations.d.ts +2 -4
- package/dist/better-auth/plugin/lib/build-collections/invitations.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/build-collections/invitations.js +75 -70
- package/dist/better-auth/plugin/lib/build-collections/jwks.d.ts +3 -5
- package/dist/better-auth/plugin/lib/build-collections/jwks.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/build-collections/jwks.js +46 -28
- package/dist/better-auth/plugin/lib/build-collections/members.d.ts +3 -5
- package/dist/better-auth/plugin/lib/build-collections/members.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/build-collections/members.js +52 -48
- package/dist/better-auth/plugin/lib/build-collections/oauth-access-tokens.d.ts +3 -5
- package/dist/better-auth/plugin/lib/build-collections/oauth-access-tokens.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/build-collections/oauth-access-tokens.js +74 -64
- package/dist/better-auth/plugin/lib/build-collections/oauth-applications.d.ts +3 -5
- package/dist/better-auth/plugin/lib/build-collections/oauth-applications.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/build-collections/oauth-applications.js +78 -71
- package/dist/better-auth/plugin/lib/build-collections/oauth-consents.d.ts +3 -5
- package/dist/better-auth/plugin/lib/build-collections/oauth-consents.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/build-collections/oauth-consents.js +68 -45
- package/dist/better-auth/plugin/lib/build-collections/organizations.d.ts +3 -5
- package/dist/better-auth/plugin/lib/build-collections/organizations.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/build-collections/organizations.js +52 -39
- package/dist/better-auth/plugin/lib/build-collections/passkeys.d.ts +3 -5
- package/dist/better-auth/plugin/lib/build-collections/passkeys.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/build-collections/passkeys.js +60 -64
- package/dist/better-auth/plugin/lib/build-collections/sessions.d.ts +3 -7
- package/dist/better-auth/plugin/lib/build-collections/sessions.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/build-collections/sessions.js +100 -98
- package/dist/better-auth/plugin/lib/build-collections/sso-providers.d.ts +3 -5
- package/dist/better-auth/plugin/lib/build-collections/sso-providers.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/build-collections/sso-providers.js +56 -56
- package/dist/better-auth/plugin/lib/build-collections/subscriptions.d.ts +4 -0
- package/dist/better-auth/plugin/lib/build-collections/subscriptions.d.ts.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/subscriptions.js +113 -0
- package/dist/better-auth/plugin/lib/build-collections/teams.d.ts +3 -5
- package/dist/better-auth/plugin/lib/build-collections/teams.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/build-collections/teams.js +62 -30
- package/dist/better-auth/plugin/lib/build-collections/two-factors.d.ts +3 -5
- package/dist/better-auth/plugin/lib/build-collections/two-factors.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/build-collections/two-factors.js +50 -37
- package/dist/better-auth/plugin/lib/build-collections/users/better-auth-strategy.js +4 -4
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/generate-invite-url.js +3 -3
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/index.d.ts +6 -0
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/index.d.ts.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/index.js +7 -0
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/set-admin-role.js +4 -4
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/signup.d.ts +2 -2
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/signup.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/signup.js +93 -96
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/after-login.d.ts +1 -6
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/after-login.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/after-login.js +22 -13
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/after-logout.d.ts +1 -5
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/after-logout.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/after-logout.js +16 -8
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/before-delete.d.ts +2 -6
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/before-delete.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/before-delete.js +25 -6
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/before-login.d.ts +2 -1
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/before-login.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/before-login.js +5 -8
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/index.d.ts +7 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/index.d.ts.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/index.js +8 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/on-verified-change.d.ts +1 -1
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/on-verified-change.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/on-verified-change.js +15 -12
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/sync-account.d.ts +1 -6
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/sync-account.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/sync-account.js +21 -10
- package/dist/better-auth/plugin/lib/build-collections/users/index.d.ts +3 -7
- package/dist/better-auth/plugin/lib/build-collections/users/index.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/build-collections/users/index.js +153 -210
- package/dist/better-auth/plugin/lib/build-collections/utils/collection-schema.d.ts +16 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/collection-schema.d.ts.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/collection-schema.js +32 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/get-timestamp-fields.d.ts +1 -1
- package/dist/better-auth/plugin/lib/build-collections/utils/get-timestamp-fields.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/build-collections/utils/get-timestamp-fields.js +1 -1
- package/dist/better-auth/plugin/lib/build-collections/utils/model-field-transformations.d.ts +17 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/model-field-transformations.d.ts.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/model-field-transformations.js +21 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/transform-schema-fields-to-payload.d.ts +22 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/transform-schema-fields-to-payload.d.ts.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/transform-schema-fields-to-payload.js +95 -0
- package/dist/better-auth/plugin/lib/build-collections/verifications.d.ts +3 -6
- package/dist/better-auth/plugin/lib/build-collections/verifications.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/build-collections/verifications.js +62 -40
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/admin-plugin.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/admin-plugin.js +4 -3
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/api-key-plugin.d.ts +2 -1
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/api-key-plugin.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/api-key-plugin.js +8 -15
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/index.d.ts +5 -3
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/index.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/index.js +56 -69
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/oidc-plugin.d.ts +2 -1
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/oidc-plugin.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/oidc-plugin.js +16 -55
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/organizations-plugin.d.ts +2 -1
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/organizations-plugin.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/organizations-plugin.js +21 -83
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/passkey-plugin.d.ts +2 -1
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/passkey-plugin.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/passkey-plugin.js +8 -15
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/sso-plugin.d.ts +2 -1
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/sso-plugin.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/sso-plugin.js +8 -15
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/two-factor-plugin.d.ts +3 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/two-factor-plugin.d.ts.map +1 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/two-factor-plugin.js +10 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/require-admin-invite-for-sign-up-middleware.d.ts +3 -3
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/require-admin-invite-for-sign-up-middleware.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/require-admin-invite-for-sign-up-middleware.js +3 -3
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/save-to-jwt-middleware.d.ts +5 -4
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/save-to-jwt-middleware.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/save-to-jwt-middleware.js +10 -10
- package/dist/better-auth/plugin/lib/set-login-methods.d.ts +1 -1
- package/dist/better-auth/plugin/lib/set-login-methods.d.ts.map +1 -1
- package/dist/better-auth/plugin/lib/set-login-methods.js +5 -6
- package/dist/better-auth/plugin/payload/views/admin-login/client.d.ts.map +1 -1
- package/dist/better-auth/plugin/payload/views/admin-login/client.js +2 -2
- package/dist/better-auth/plugin/payload/views/admin-login/index.d.ts +4 -4
- package/dist/better-auth/plugin/payload/views/admin-login/index.d.ts.map +1 -1
- package/dist/better-auth/plugin/payload/views/admin-login/index.js +7 -8
- package/dist/better-auth/plugin/payload/views/admin-signup/client.d.ts +1 -1
- package/dist/better-auth/plugin/payload/views/admin-signup/client.d.ts.map +1 -1
- package/dist/better-auth/plugin/payload/views/admin-signup/client.js +27 -7
- package/dist/better-auth/plugin/payload/views/admin-signup/index.d.ts +4 -5
- package/dist/better-auth/plugin/payload/views/admin-signup/index.d.ts.map +1 -1
- package/dist/better-auth/plugin/payload/views/admin-signup/index.js +6 -6
- package/dist/better-auth/plugin/payload/views/forgot-password/index.d.ts +1 -5
- package/dist/better-auth/plugin/payload/views/forgot-password/index.d.ts.map +1 -1
- package/dist/better-auth/plugin/payload/views/forgot-password/index.js +1 -1
- package/dist/better-auth/plugin/payload/views/two-factor-verify/index.d.ts +3 -3
- package/dist/better-auth/plugin/payload/views/two-factor-verify/index.d.ts.map +1 -1
- package/dist/better-auth/plugin/payload/views/two-factor-verify/index.js +10 -7
- package/dist/better-auth/plugin/types.d.ts +41 -13
- package/dist/better-auth/plugin/types.d.ts.map +1 -1
- package/dist/better-auth/plugin/types.js +1 -1
- package/dist/better-auth/plugin/utils/set.d.ts +40 -0
- package/dist/better-auth/plugin/utils/set.d.ts.map +1 -0
- package/dist/better-auth/plugin/utils/set.js +84 -0
- package/dist/better-auth/scripts/generate-types.d.ts +2 -0
- package/dist/better-auth/scripts/generate-types.d.ts.map +1 -0
- package/dist/better-auth/scripts/generate-types.js +219 -0
- package/dist/shared/form/validation.d.ts +31 -7
- package/dist/shared/form/validation.d.ts.map +1 -1
- package/dist/shared/form/validation.js +13 -5
- package/package.json +14 -9
- package/dist/better-auth/plugin/helpers/check-passkey-plugin.d.ts +0 -3
- package/dist/better-auth/plugin/helpers/check-passkey-plugin.d.ts.map +0 -1
- package/dist/better-auth/plugin/helpers/check-passkey-plugin.js +0 -6
- package/dist/better-auth/plugin/helpers/check-two-factor-plugin.d.ts +0 -3
- package/dist/better-auth/plugin/helpers/check-two-factor-plugin.d.ts.map +0 -1
- package/dist/better-auth/plugin/helpers/check-two-factor-plugin.js +0 -6
- package/dist/better-auth/plugin/helpers/check-username-plugin.d.ts +0 -3
- package/dist/better-auth/plugin/helpers/check-username-plugin.d.ts.map +0 -1
- package/dist/better-auth/plugin/helpers/check-username-plugin.js +0 -6
- package/dist/better-auth/plugin/lib/get-required-collection-slugs.d.ts +0 -10
- package/dist/better-auth/plugin/lib/get-required-collection-slugs.d.ts.map +0 -1
- package/dist/better-auth/plugin/lib/get-required-collection-slugs.js +0 -35
- package/dist/better-auth/plugin/payload/utils/generate-metadata.d.ts +0 -15
- package/dist/better-auth/plugin/payload/utils/generate-metadata.d.ts.map +0 -1
- package/dist/better-auth/plugin/payload/utils/generate-metadata.js +0 -74
|
@@ -1,9 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
import { baModelKey } from "../../../../constants";
|
|
2
|
+
import { getMappedCollection, transformCollectionsToCollectionConfigs } from "../../../../helpers/get-collection";
|
|
3
|
+
import { commitTransaction, initTransaction, killTransaction } from "payload";
|
|
4
|
+
export function getBeforeDeleteHook() {
|
|
2
5
|
const hook = async ({ req, id })=>{
|
|
6
|
+
const collections = req.payload.collections;
|
|
7
|
+
const collectionMap = transformCollectionsToCollectionConfigs(collections);
|
|
8
|
+
const accountsSlug = getMappedCollection({
|
|
9
|
+
collectionMap,
|
|
10
|
+
betterAuthModelKey: baModelKey.account
|
|
11
|
+
}).slug;
|
|
12
|
+
const sessionsSlug = getMappedCollection({
|
|
13
|
+
collectionMap,
|
|
14
|
+
betterAuthModelKey: baModelKey.session
|
|
15
|
+
}).slug;
|
|
16
|
+
const verificationsSlug = getMappedCollection({
|
|
17
|
+
collectionMap,
|
|
18
|
+
betterAuthModelKey: baModelKey.verification
|
|
19
|
+
}).slug;
|
|
3
20
|
try {
|
|
4
21
|
const { payload } = req;
|
|
5
22
|
const userId = id;
|
|
6
|
-
|
|
23
|
+
const shouldCommit = await initTransaction(req);
|
|
7
24
|
await payload.delete({
|
|
8
25
|
collection: accountsSlug,
|
|
9
26
|
where: {
|
|
@@ -13,7 +30,6 @@ export const getBeforeDeleteHook = ({ accountsSlug, sessionsSlug, verificationsS
|
|
|
13
30
|
},
|
|
14
31
|
req
|
|
15
32
|
});
|
|
16
|
-
// Delete sessions
|
|
17
33
|
await payload.delete({
|
|
18
34
|
collection: sessionsSlug,
|
|
19
35
|
where: {
|
|
@@ -23,7 +39,6 @@ export const getBeforeDeleteHook = ({ accountsSlug, sessionsSlug, verificationsS
|
|
|
23
39
|
},
|
|
24
40
|
req
|
|
25
41
|
});
|
|
26
|
-
// Delete any verifications
|
|
27
42
|
await payload.delete({
|
|
28
43
|
collection: verificationsSlug,
|
|
29
44
|
where: {
|
|
@@ -33,13 +48,17 @@ export const getBeforeDeleteHook = ({ accountsSlug, sessionsSlug, verificationsS
|
|
|
33
48
|
},
|
|
34
49
|
req
|
|
35
50
|
});
|
|
51
|
+
if (shouldCommit) {
|
|
52
|
+
await commitTransaction(req);
|
|
53
|
+
}
|
|
36
54
|
return;
|
|
37
55
|
} catch (error) {
|
|
56
|
+
await killTransaction(req);
|
|
38
57
|
console.error('Error in user afterDelete hook:', error);
|
|
39
58
|
return;
|
|
40
59
|
}
|
|
41
60
|
};
|
|
42
61
|
return hook;
|
|
43
|
-
}
|
|
62
|
+
}
|
|
44
63
|
|
|
45
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
64
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3NyYy9iZXR0ZXItYXV0aC9wbHVnaW4vbGliL2J1aWxkLWNvbGxlY3Rpb25zL3VzZXJzL2hvb2tzL2JlZm9yZS1kZWxldGUudHMiXSwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHsgYmFNb2RlbEtleSB9IGZyb20gJ0AvYmV0dGVyLWF1dGgvcGx1Z2luL2NvbnN0YW50cydcbmltcG9ydCB7IGdldE1hcHBlZENvbGxlY3Rpb24sIHRyYW5zZm9ybUNvbGxlY3Rpb25zVG9Db2xsZWN0aW9uQ29uZmlncyB9IGZyb20gJ0AvYmV0dGVyLWF1dGgvcGx1Z2luL2hlbHBlcnMvZ2V0LWNvbGxlY3Rpb24nXG5pbXBvcnQgeyBjb21taXRUcmFuc2FjdGlvbiwgaW5pdFRyYW5zYWN0aW9uLCBraWxsVHJhbnNhY3Rpb24sIHR5cGUgQ29sbGVjdGlvbkJlZm9yZURlbGV0ZUhvb2sgfSBmcm9tICdwYXlsb2FkJ1xuXG5leHBvcnQgZnVuY3Rpb24gZ2V0QmVmb3JlRGVsZXRlS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ZXF1YWxzOiB1c2VySWRcbiAgICAgICAgICB9XG4gICAgICAgIH0sXG4gICAgICAgIHJlcVxuICAgICAgfSlcblxuICAgICAgYXdhaXQgcGF5bG9hZC5kZWxldGUoe1xuICAgICAgICBjb2xsZWN0aW9uOiBzZXNzaW9uc1NsdWcsXG4gICAgICAgIHdoZXJlOiB7XG4gICAgICAgICAgdXNlcjoge1xuICAgICAgICAgICAgZXF1YWxzOiB1c2VySWRcbiAgICAgICAgICB9XG4gICAgICAgIH0sXG4gICAgICAgIHJlcVxuICAgICAgfSlcblxuICAgICAgYXdhaXQgcGF5bG9hZC5kZWxldGUoe1xuICAgICAgICBjb2xsZWN0aW9uOiB2ZXJpZmljYXRpb25zU2x1ZyxcbiAgICAgICAgd2hlcmU6IHtcbiAgICAgICAgICB2YWx1ZToge1xuICAgICAgICAgICAgbGlrZTogYFwiJHt1c2VySWR9XCJgXG4gICAgICAgICAgfVxuICAgICAgICB9LFxuICAgICAgICByZXFcbiAgICAgIH0pXG5cbiAgICAgIGlmIChzaG91bGRDb21taXQpIHtcbiAgICAgICAgYXdhaXQgY29tbWl0VHJhbnNhY3Rpb24ocmVxKVxuICAgICAgfVxuXG4gICAgICByZXR1cm5cbiAgICB9IGNhdGNoIChlcnJvcikge1xuICAgICAgYXdhaXQga2lsbFRyYW5zYWN0aW9uKHJlcSlcbiAgICAgIGNvbnNvbGUuZXJyb3IoJ0Vycm9yIGluIHVzZXIgYWZ0ZXJEZWxldGUgaG9vazonLCBlcnJvcilcbiAgICAgIHJldHVyblxuICAgIH1cbiAgfVxuXG4gIHJldHVybiBob29rXG59XG4iXSwibmFtZXMiOlsiYmFNb2RlbEtleSIsImdldE1hcHBlZENvbGxlY3Rpb24iLCJ0cmFuc2Zvcm1Db2xsZWN0aW9uc1RvQ29sbGVjdGlvbkNvbmZpZ3MiLCJjb21taXRUcmFuc2FjdGlvbiIsImluaXRUcmFuc2FjdGlvbiIsImtpbGxUcmFuc2FjdGlvbiIsImdldEJlZm9y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SUFBSTtZQUNGLE1BQU0sRUFBRUwsT0FBTyxFQUFFLEdBQUdIO1lBQ3BCLE1BQU1hLFNBQVNaO1lBRWYsTUFBTWEsZUFBZSxNQUFNbEIsZ0JBQWdCSTtZQUUzQyxNQUFNRyxRQUFRWSxNQUFNLENBQUM7Z0JBQ25CQyxZQUFZWDtnQkFDWlksT0FBTztvQkFDTEMsTUFBTTt3QkFDSkMsUUFBUU47b0JBQ1Y7Z0JBQ0Y7Z0JBQ0FiO1lBQ0Y7WUFFQSxNQUFNRyxRQUFRWSxNQUFNLENBQUM7Z0JBQ25CQyxZQUFZUDtnQkFDWlEsT0FBTztvQkFDTEMsTUFBTTt3QkFDSkMsUUFBUU47b0JBQ1Y7Z0JBQ0Y7Z0JBQ0FiO1lBQ0Y7WUFFQSxNQUFNRyxRQUFRWSxNQUFNLENBQUM7Z0JBQ25CQyxZQUFZTDtnQkFDWk0sT0FBTztvQkFDTEcsT0FBTzt3QkFDTEMsTUFBTSxDQUFDLENBQUMsRUFBRVIsT0FBTyxDQUFDLENBQUM7b0JBQ3JCO2dCQUNGO2dCQUNBYjtZQUNGO1lBRUEsSUFBSWMsY0FBYztnQkFDaEIsTUFBTW5CLGtCQUFrQks7WUFDMUI7WUFFQTtRQUNGLEVBQUUsT0FBT3NCLE9BQU87WUFDZCxNQUFNekIsZ0JBQWdCRztZQUN0QnVCLFFBQVFELEtBQUssQ0FBQyxtQ0FBbUNBO1lBQ2pEO1FBQ0Y7SUFDRjtJQUVBLE9BQU92QjtBQUNUIn0=
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CollectionBeforeLoginHook } from 'payload';
|
|
2
|
+
import type { BetterAuthOptions } from '@/better-auth/plugin/types';
|
|
2
3
|
/**
|
|
3
4
|
* This hook blocks login attempts if email verification is required and the user's email is not verified
|
|
4
5
|
*/
|
|
5
|
-
export declare
|
|
6
|
+
export declare function getBeforeLoginHook(betterAuthOptions: BetterAuthOptions): CollectionBeforeLoginHook;
|
|
6
7
|
//# sourceMappingURL=before-login.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"before-login.d.ts","sourceRoot":"","sources":["../../../../../../../src/better-auth/plugin/lib/build-collections/users/hooks/before-login.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,yBAAyB,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"before-login.d.ts","sourceRoot":"","sources":["../../../../../../../src/better-auth/plugin/lib/build-collections/users/hooks/before-login.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,yBAAyB,EAAE,MAAM,SAAS,CAAA;AAC7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AACnE;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,iBAAiB,EAAE,iBAAiB,6BAYtE"}
|
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
import { APIError } from "payload";
|
|
2
|
-
import { getPayloadAuth } from "../../../get-payload-auth";
|
|
3
2
|
/**
|
|
4
3
|
* This hook blocks login attempts if email verification is required and the user's email is not verified
|
|
5
|
-
*/ export
|
|
6
|
-
const hook = async ({
|
|
7
|
-
const
|
|
8
|
-
const payload = await getPayloadAuth(config);
|
|
9
|
-
const requireEmailVerification = payload.betterAuth.options.emailAndPassword?.requireEmailVerification ?? false;
|
|
4
|
+
*/ export function getBeforeLoginHook(betterAuthOptions) {
|
|
5
|
+
const hook = async ({ user })=>{
|
|
6
|
+
const requireEmailVerification = betterAuthOptions.emailAndPassword?.requireEmailVerification ?? false;
|
|
10
7
|
if (requireEmailVerification && !user.emailVerified) {
|
|
11
8
|
throw new APIError('Email verification required. Please verify your email before logging in.', 403);
|
|
12
9
|
}
|
|
13
10
|
return user;
|
|
14
11
|
};
|
|
15
12
|
return hook;
|
|
16
|
-
}
|
|
13
|
+
}
|
|
17
14
|
|
|
18
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
15
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJz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H1cblxuICAgIHJldHVybiB1c2VyXG4gIH1cblxuICByZXR1cm4gaG9va1xufVxuIl0sIm5hbWVzIjpbIkFQSUVycm9yIiwiZ2V0QmVmb3JlTG9naW5Ib29rIiwiYmV0dGVyQXV0aE9wdGlvbnMiLCJob29rIiwidXNlciIsInJlcXVpcmVFbWFpbFZlcmlmaWNhdGlvbiIsImVtYWlsQW5kUGFzc3dvcmQiLCJlbWFpbFZlcmlmaWVkIl0sIm1hcHBpbmdzIjoiQUFBQSxTQUFTQSxRQUFRLFFBQW1DLFVBQVM7QUFFN0Q7O0NBRUMsR0FDRCxPQUFPLFNBQVNDLG1CQUFtQkMsaUJBQW9DO0lBQ3JFLE1BQU1DLE9BQWtDLE9BQU8sRUFBRUMsSUFBSSxFQUFFO1FBQ3JELE1BQU1DLDJCQUEyQkgsa0JBQWtCSSxnQkFBZ0IsRUFBRUQsNEJBQTRCO1FBRWpHLElBQUlBLDRCQUE0QixDQUFDRCxLQUFLRyxhQUFhLEVBQUU7WUFDbkQsTUFBTSxJQUFJUCxTQUFTLDRFQUE0RTtRQUNqRztRQUVBLE9BQU9JO0lBQ1Q7SUFFQSxPQUFPRDtBQUNUIn0=
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../src/better-auth/plugin/lib/build-collections/users/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,sBAAsB,CAAA;AACpC,cAAc,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./after-login";
|
|
2
|
+
export * from "./after-logout";
|
|
3
|
+
export * from "./before-delete";
|
|
4
|
+
export * from "./before-login";
|
|
5
|
+
export * from "./on-verified-change";
|
|
6
|
+
export * from "./sync-account";
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3NyYy9iZXR0ZXItYXV0aC9wbHVnaW4vbGliL2J1aWxkLWNvbGxlY3Rpb25zL3VzZXJzL2hvb2tzL2luZGV4LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCAqIGZyb20gJy4vYWZ0ZXItbG9naW4nXG5leHBvcnQgKiBmcm9tICcuL2FmdGVyLWxvZ291dCdcbmV4cG9ydCAqIGZyb20gJy4vYmVmb3JlLWRlbGV0ZSdcbmV4cG9ydCAqIGZyb20gJy4vYmVmb3JlLWxvZ2luJ1xuZXhwb3J0ICogZnJvbSAnLi9vbi12ZXJpZmllZC1jaGFuZ2UnXG5leHBvcnQgKiBmcm9tICcuL3N5bmMtYWNjb3VudCdcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLGdCQUFlO0FBQzdCLGNBQWMsaUJBQWdCO0FBQzlCLGNBQWMsa0JBQWlCO0FBQy9CLGNBQWMsaUJBQWdCO0FBQzlCLGNBQWMsdUJBQXNCO0FBQ3BDLGNBQWMsaUJBQWdCIn0=
|
package/dist/better-auth/plugin/lib/build-collections/users/hooks/on-verified-change.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"on-verified-change.d.ts","sourceRoot":"","sources":["../../../../../../../src/better-auth/plugin/lib/build-collections/users/hooks/on-verified-change.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAA;AAEpD,
|
|
1
|
+
{"version":3,"file":"on-verified-change.d.ts","sourceRoot":"","sources":["../../../../../../../src/better-auth/plugin/lib/build-collections/users/hooks/on-verified-change.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAA;AAEpD,wBAAgB,uBAAuB,+BAiBtC"}
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
export
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
export function getOnVerifiedChangeHook() {
|
|
2
|
+
const hook = async ({ data, originalDoc })=>{
|
|
3
|
+
const isVerifiedChangingToTrue = Boolean(data._verified) && !Boolean(originalDoc?._verified);
|
|
4
|
+
const isEmailVerifiedChangingToTrue = Boolean(data.emailVerified) && !Boolean(originalDoc?.emailVerified);
|
|
5
|
+
if (!isVerifiedChangingToTrue && !isEmailVerifiedChangingToTrue) {
|
|
6
|
+
return data;
|
|
7
|
+
}
|
|
8
|
+
return {
|
|
9
|
+
...data,
|
|
10
|
+
_verified: true,
|
|
11
|
+
emailVerified: true
|
|
12
|
+
};
|
|
11
13
|
};
|
|
12
|
-
|
|
14
|
+
return hook;
|
|
15
|
+
}
|
|
13
16
|
|
|
14
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
17
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3NyYy9iZXR0ZXItYXV0aC9wbHVnaW4vbGliL2J1aWxkLWNvbGxlY3Rpb25zL3VzZXJzL2hvb2tzL29uLXZlcmlmaWVkLWNoYW5nZS50cyJdLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgeyBDb2xsZWN0aW9uQmVmb3JlQ2hhbmdlSG9vayB9IGZyb20gJ3BheWxvYWQnXG5cbmV4cG9ydCBmdW5jdGlvbiBnZXRPblZlcmlmaWVkQ2hhbmdlSG9vaygpIHtcbiAgY29uc3QgaG9vazogQ29sbGVjdGlvbkJlZm9yZUNoYW5nZUhvb2sgPSBhc3luYyAoeyBkYXRhLCBvcmlnaW5hbERvYyB9KSA9PiB7XG4gICAgY29uc3QgaXNWZXJpZmllZENoYW5naW5nVG9UcnVlID0gQm9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NUO1FBRUEsT0FBTztZQUNMLEdBQUdBLElBQUk7WUFDUEksV0FBVztZQUNYRSxlQUFlO1FBQ2pCO0lBQ0Y7SUFFQSxPQUFPUDtBQUNUIn0=
|
|
@@ -1,8 +1,3 @@
|
|
|
1
1
|
import type { CollectionAfterChangeHook } from 'payload';
|
|
2
|
-
|
|
3
|
-
userSlug: string;
|
|
4
|
-
accountSlug: string;
|
|
5
|
-
};
|
|
6
|
-
export declare const getSyncAccountHook: (options: SyncAccountOptions) => CollectionAfterChangeHook;
|
|
7
|
-
export {};
|
|
2
|
+
export declare function getSyncAccountHook(): CollectionAfterChangeHook;
|
|
8
3
|
//# sourceMappingURL=sync-account.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-account.d.ts","sourceRoot":"","sources":["../../../../../../../src/better-auth/plugin/lib/build-collections/users/hooks/sync-account.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sync-account.d.ts","sourceRoot":"","sources":["../../../../../../../src/better-auth/plugin/lib/build-collections/users/hooks/sync-account.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAA;AAExD,wBAAgB,kBAAkB,IAAI,yBAAyB,CA0E9D"}
|
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
import { BETTER_AUTH_CONTEXT_KEY } from "../../../../../adapter";
|
|
2
|
-
|
|
2
|
+
import { baModelKey } from "../../../../constants";
|
|
3
|
+
import { getMappedCollection, transformCollectionsToCollectionConfigs } from "../../../../helpers/get-collection";
|
|
4
|
+
export function getSyncAccountHook() {
|
|
3
5
|
const hook = async ({ doc, req, operation, context })=>{
|
|
4
6
|
if (context?.syncPasswordToUser) return doc;
|
|
5
7
|
if (operation !== 'create' && operation !== 'update') return doc;
|
|
8
|
+
const collections = req.payload.collections;
|
|
9
|
+
const collectionMap = transformCollectionsToCollectionConfigs(collections);
|
|
10
|
+
const userSlug = getMappedCollection({
|
|
11
|
+
collectionMap,
|
|
12
|
+
betterAuthModelKey: baModelKey.user
|
|
13
|
+
})?.slug;
|
|
14
|
+
const accountSlug = getMappedCollection({
|
|
15
|
+
collectionMap,
|
|
16
|
+
betterAuthModelKey: baModelKey.account
|
|
17
|
+
})?.slug;
|
|
6
18
|
const user = await req.payload.findByID({
|
|
7
|
-
collection:
|
|
19
|
+
collection: userSlug,
|
|
8
20
|
id: doc.id,
|
|
9
21
|
depth: 0,
|
|
10
22
|
req,
|
|
@@ -12,13 +24,12 @@ export const getSyncAccountHook = (options)=>{
|
|
|
12
24
|
});
|
|
13
25
|
if (!user || !user.hash || !user.salt) return doc;
|
|
14
26
|
const passwordValue = `${user.salt}:${user.hash}`;
|
|
15
|
-
const userField = req.payload.betterAuth.options.account?.fields?.userId || 'userId';
|
|
16
27
|
if (operation === 'create' && !(BETTER_AUTH_CONTEXT_KEY in context)) {
|
|
17
28
|
try {
|
|
18
29
|
await req.payload.create({
|
|
19
|
-
collection:
|
|
30
|
+
collection: accountSlug,
|
|
20
31
|
data: {
|
|
21
|
-
|
|
32
|
+
userId: doc.id,
|
|
22
33
|
accountId: doc.id.toString(),
|
|
23
34
|
providerId: 'credential',
|
|
24
35
|
password: passwordValue,
|
|
@@ -35,11 +46,11 @@ export const getSyncAccountHook = (options)=>{
|
|
|
35
46
|
if (operation === 'update') {
|
|
36
47
|
try {
|
|
37
48
|
const accounts = await req.payload.find({
|
|
38
|
-
collection:
|
|
49
|
+
collection: accountSlug,
|
|
39
50
|
where: {
|
|
40
51
|
and: [
|
|
41
52
|
{
|
|
42
|
-
|
|
53
|
+
userId: {
|
|
43
54
|
equals: doc.id
|
|
44
55
|
}
|
|
45
56
|
},
|
|
@@ -59,7 +70,7 @@ export const getSyncAccountHook = (options)=>{
|
|
|
59
70
|
const account = accounts.docs.at(0);
|
|
60
71
|
if (account) {
|
|
61
72
|
await req.payload.update({
|
|
62
|
-
collection:
|
|
73
|
+
collection: accountSlug,
|
|
63
74
|
id: account.id,
|
|
64
75
|
data: {
|
|
65
76
|
password: passwordValue
|
|
@@ -77,6 +88,6 @@ export const getSyncAccountHook = (options)=>{
|
|
|
77
88
|
return doc;
|
|
78
89
|
};
|
|
79
90
|
return hook;
|
|
80
|
-
}
|
|
91
|
+
}
|
|
81
92
|
|
|
82
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
93
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3NyYy9iZXR0ZXItYXV0aC9wbHVnaW4vbGliL2J1aWxkLWNvbGxlY3Rpb25zL3VzZXJzL2hvb2tzL3N5bmMtYWNjb3VudC50cyJdLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgeyBCRVRURVJfQVVUSF9DT05URVhUX0tFWSB9IGZyb20gJ0AvYmV0dGVyLWF1dGgvYWRhcHRlcidcbmltcG9ydCB7IGJhTW9kZWxLZXkgfSBmcm9tICdAL2JldHRlci1hdXRoL3BsdWdpbi9jb25zdGFudHMnXG5pbXBvcnQgeyBnZXRNYXBwZWRDb2xsZWN0aW9uLCB0cmFuc2Zvcm1Db2xsZWN0aW9uc1RvQ29sbGVjdGlvbkNvbmZpZ3MgfSBmcm9tICdAL2JldHRlci1hdXRoL3BsdWdpbi9oZWxwZXJzL2dldC1jb2xsZWN0aW9uJ1xuaW1wb3J0IHR5cGUgeyBDb2xsZWN0aW9uQWZ0ZXJDaGFuZ2VIb29rIH0gZnJvbSAncGF5bG9hZCdcblxuZXhwb3J0IGZ1bmN0aW9uIGdldFN5bmNBY2NvdW50SG9vaygpOiBDb2xsZWN0aW9uQWZ0ZXJDaGFuZ2VIb29rIHtcbiAgY29uc3QgaG9vazogQ29sbGVjdGlvbkFmdGVyQ2hhbmdlSG9vayA9IGFzeW5jICh7IGRvYywgcmVxLCBvcGVyYXRpb24sIGNvbnRleHQgfSkgPT4ge1xuICAgIGlmIChjb250ZXh0Py5zeW5jUGFz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gICAgICAgYXdhaXQgcmVxLnBheWxvYWQuY3JlYXRlKHtcbiAgICAgICAgICBjb2xsZWN0aW9uOiBhY2NvdW50U2x1ZyxcbiAgICAgICAgICBkYXRhOiB7XG4gICAgICAgICAgICB1c2VySWQ6IGRvYy5pZCxcbiAgICAgICAgICAgIGFjY291bnRJZDogZG9jLmlkLnRvU3RyaW5nKCksXG4gICAgICAgICAgICBwcm92aWRlcklkOiAnY3JlZGVudGlhbCcsXG4gICAgICAgICAgICBwYXNzd29yZDogcGFzc3dvcmRWYWx1ZSxcbiAgICAgICAgICAgIGNvbnRleHQ6IHsgc3luY0FjY291bnRIb29rOiB0cnVlIH1cbiAgICAgICAgICB9LFxuICAgICAgICAgIHJlcVxuICAgICAgICB9KVxuICAgICAgfSBjYXRjaCAoZXJyb3IpIHtcbiAgICAgICAgY29uc29sZS5lcnJvcignRmFpbGVkIHRvIGNyZWF0ZSBhY2NvdW50IGZvciB1c2VyOicsIGVycm9yKVxuICAgICAgfVxuICAgIH1cblxuICAgIGlmIChvcGVyYXRpb24gPT09ICd1cGRhdGUnKSB7XG4gICAgICB0cnkge1xuICAgICAgICBjb25zdCBhY2NvdW50cyA9IGF3YWl0IHJlcS5wYXlsb2FkLmZpbmQoe1xuICAgICAgICAgIGNvbGxlY3Rpb246IGFjY291bnRTbHVnLFxuICAgICAgICAgIHdoZXJlOiB7XG4gICAgICAgICAgICBhbmQ6IFt7IHVzZXJJZDogeyBlcXVhbHM6IGRvYy5pZCB9IH0sIHsgcHJvdmlkZXJJZDogeyBlcXVhbHM6ICdjcmVkZW50aWFsJyB9IH1dXG4gICAgICAgICAgfSxcbiAgICAgICAgICByZXEsXG4gICAgICAgICAgZGVwdGg6IDAsXG4gICAgICAgICAgY29udGV4dDogeyBzeW5jQWNjb3VudEhvb2s6IHRydWUgfVxuICAgICAgICB9KVxuXG4gICAgICAgIGNvbnN0IGFjY291bnQgPSBhY2NvdW50cy5kb2NzLmF0KDApXG4gICAgICAgIGlmIChhY2N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ztnQkFFQSxNQUFNaEIsVUFBVW1CLFNBQVNLLElBQUksQ0FBQ0MsRUFBRSxDQUFDO2dCQUNqQyxJQUFJekIsU0FBUztvQkFDWCxNQUFNWixJQUFJSyxPQUFPLENBQUNpQyxNQUFNLENBQUM7d0JBQ3ZCeEIsWUFBWUg7d0JBQ1pJLElBQUlILFFBQVFHLEVBQUU7d0JBQ2RPLE1BQU07NEJBQ0pLLFVBQVVQO3dCQUNaO3dCQUNBcEI7d0JBQ0FFLFNBQVM7NEJBQUUwQixpQkFBaUI7d0JBQUs7b0JBQ25DO2dCQUNGO1lBQ0YsRUFBRSxPQUFPQyxPQUFPO2dCQUNkQyxRQUFRRCxLQUFLLENBQUMsd0NBQXdDQTtZQUN4RDtRQUNGO1FBRUEsT0FBTzlCO0lBQ1Q7SUFFQSxPQUFPRDtBQUNUIn0=
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import { CollectionConfig } from 'payload';
|
|
2
|
-
import type {
|
|
3
|
-
export declare function buildUsersCollection({ incomingCollections, pluginOptions,
|
|
4
|
-
incomingCollections: CollectionConfig[];
|
|
5
|
-
pluginOptions: BetterAuthPluginOptions;
|
|
6
|
-
betterAuthOptions: SanitizedBetterAuthOptions;
|
|
7
|
-
}): CollectionConfig;
|
|
1
|
+
import type { CollectionConfig } from 'payload';
|
|
2
|
+
import type { BuildCollectionProps } from '../../../types';
|
|
3
|
+
export declare function buildUsersCollection({ incomingCollections, pluginOptions, schema }: BuildCollectionProps): CollectionConfig;
|
|
8
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/better-auth/plugin/lib/build-collections/users/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/better-auth/plugin/lib/build-collections/users/index.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C,OAAO,KAAK,EAAE,oBAAoB,EAAkB,MAAM,gBAAgB,CAAA;AAG1E,wBAAgB,oBAAoB,CAAC,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,EAAE,EAAE,oBAAoB,GAAG,gBAAgB,CAwN3H"}
|