@dodopayments/better-auth 1.0.1 → 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/client.d.ts +0 -1
- package/dist/client.js +6 -0
- package/dist/hooks/customer.d.ts +0 -1
- package/dist/hooks/customer.js +63 -0
- package/dist/index.d.ts +144 -743
- package/dist/index.js +6 -17751
- package/dist/plugins/checkout.d.ts +0 -1
- package/dist/plugins/checkout.js +87 -0
- package/dist/plugins/portal.d.ts +0 -1
- package/dist/plugins/portal.js +173 -0
- package/dist/plugins/webhooks.d.ts +0 -1
- package/dist/plugins/webhooks.js +62 -0
- package/dist/types.d.ts +0 -1
- package/dist/types.js +1 -0
- package/package.json +6 -3
- package/dist/client.d.ts.map +0 -1
- package/dist/hooks/customer.d.ts.map +0 -1
- package/dist/index.cjs +0 -17806
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/plugins/checkout.d.ts.map +0 -1
- package/dist/plugins/portal.d.ts.map +0 -1
- package/dist/plugins/webhooks.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
package/dist/client.d.ts
CHANGED
package/dist/client.js
ADDED
package/dist/hooks/customer.d.ts
CHANGED
|
@@ -2,4 +2,3 @@ import type { GenericEndpointContext, User } from "better-auth";
|
|
|
2
2
|
import type { DodoPaymentsOptions } from "../types";
|
|
3
3
|
export declare const onUserCreate: (options: DodoPaymentsOptions) => (user: User, ctx?: GenericEndpointContext) => Promise<void>;
|
|
4
4
|
export declare const onUserUpdate: (options: DodoPaymentsOptions) => (user: User, ctx?: GenericEndpointContext) => Promise<void>;
|
|
5
|
-
//# sourceMappingURL=customer.d.ts.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { APIError } from "better-auth/api";
|
|
2
|
+
export const onUserCreate = (options) => async (user, ctx) => {
|
|
3
|
+
if (ctx && options.createCustomerOnSignUp) {
|
|
4
|
+
try {
|
|
5
|
+
const customers = await options.client.customers.list({
|
|
6
|
+
email: user.email,
|
|
7
|
+
});
|
|
8
|
+
const existingCustomer = customers.items[0];
|
|
9
|
+
if (existingCustomer) {
|
|
10
|
+
if (existingCustomer.email !== user.email) {
|
|
11
|
+
await options.client.customers.update(existingCustomer.customer_id, {
|
|
12
|
+
name: user.name,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
// TODO: Add metadata to customer object via
|
|
18
|
+
// getCustomerCreateParams option when it becomes
|
|
19
|
+
// available in the API
|
|
20
|
+
await options.client.customers.create({
|
|
21
|
+
email: user.email,
|
|
22
|
+
name: user.name,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
if (e instanceof Error) {
|
|
28
|
+
throw new APIError("INTERNAL_SERVER_ERROR", {
|
|
29
|
+
message: `DodoPayments customer creation failed. Error: ${e.message}`,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
throw new APIError("INTERNAL_SERVER_ERROR", {
|
|
33
|
+
message: `DodoPayments customer creation failed. Error: ${e}`,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
export const onUserUpdate = (options) => async (user, ctx) => {
|
|
39
|
+
if (ctx && options.createCustomerOnSignUp) {
|
|
40
|
+
try {
|
|
41
|
+
const customers = await options.client.customers.list({
|
|
42
|
+
email: user.email,
|
|
43
|
+
});
|
|
44
|
+
const existingCustomer = customers.items[0];
|
|
45
|
+
if (existingCustomer) {
|
|
46
|
+
// TODO: Add metadata to customer object via
|
|
47
|
+
// getCustomerCreateParams option when it becomes
|
|
48
|
+
// available in the API
|
|
49
|
+
await options.client.customers.update(existingCustomer.customer_id, {
|
|
50
|
+
name: user.name,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
if (e instanceof Error) {
|
|
56
|
+
ctx.context.logger.error(`DodoPayments customer update failed. Error: ${e.message}`);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
ctx.context.logger.error(`DodoPayments customer update failed. Error: ${e}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|