@unifiedcommerce/core 0.5.1 → 0.5.2
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/auth/setup.d.ts.map +1 -1
- package/dist/auth/setup.js +3 -26
- package/package.json +1 -1
- package/src/auth/setup.ts +3 -26
package/dist/auth/setup.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/auth/setup.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AACxF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/auth/setup.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AACxF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAiBrE;;;;;GAKG;AACH,KAAK,cAAc,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC;IACjD,OAAO,EAAE;QACP,UAAU,CAAC,OAAO,YAAY,CAAC;QAC/B,UAAU,CAAC,OAAO,MAAM,CAAC;QACzB,UAAU,CAAC,OAAO,GAAG,CAAC;QACtB,UAAU,CAAC,OAAO,SAAS,CAAC;QAC5B,UAAU,CAAC,OAAO,MAAM,CAAC;QACzB,UAAU,CAAC,OAAO,WAAW,CAAC;KAC/B,CAAC;CACH,CAAC,CAAC,CAAC;AAEJ;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,cAAc,CAAC;AAE1C,wBAAgB,UAAU,CACxB,EAAE,EAAE,eAAe,EACnB,MAAM,EAAE,cAAc,GACrB,YAAY,CAkHd"}
|
package/dist/auth/setup.js
CHANGED
|
@@ -60,32 +60,9 @@ export function createAuth(db, config) {
|
|
|
60
60
|
provider: resolveAuthDbProvider(db.provider),
|
|
61
61
|
schema: authSchema,
|
|
62
62
|
}),
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
after: async (user) => {
|
|
67
|
-
// Auto-create customer record on signup. Uses the Drizzle db
|
|
68
|
-
// directly because the kernel isn't fully initialized yet during
|
|
69
|
-
// auth setup. Best-effort — getByUserId() lazy-creates as fallback.
|
|
70
|
-
try {
|
|
71
|
-
const { customers } = await import("../kernel/database/schema.js");
|
|
72
|
-
const drizzle = db.db;
|
|
73
|
-
await drizzle.insert(customers).values({
|
|
74
|
-
organizationId: "org_default",
|
|
75
|
-
userId: user.id,
|
|
76
|
-
email: user.email ?? null,
|
|
77
|
-
firstName: user.name?.split(" ")[0] ?? null,
|
|
78
|
-
lastName: user.name?.split(" ").slice(1).join(" ") ?? null,
|
|
79
|
-
metadata: {},
|
|
80
|
-
}).onConflictDoNothing();
|
|
81
|
-
}
|
|
82
|
-
catch {
|
|
83
|
-
// Silent — lazy creation in getByUserId() is the fallback
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
},
|
|
63
|
+
// Customer profile creation is handled lazily by CustomerService.getByUserId()
|
|
64
|
+
// which calls getOrCreateByUserId() on first access (checkout, /api/me/profile).
|
|
65
|
+
// No databaseHook needed — admins/staff who sign up don't need customer profiles.
|
|
89
66
|
trustedOrigins: config.auth?.trustedOrigins ?? [],
|
|
90
67
|
emailAndPassword: {
|
|
91
68
|
enabled: true,
|
package/package.json
CHANGED
package/src/auth/setup.ts
CHANGED
|
@@ -5,7 +5,6 @@ import { apiKey } from "@better-auth/api-key";
|
|
|
5
5
|
import { organization, twoFactor, phoneNumber, jwt, bearer } from "better-auth/plugins";
|
|
6
6
|
import type { CommerceConfig } from "../config/types.js";
|
|
7
7
|
import type { DatabaseAdapter } from "../kernel/database/adapter.js";
|
|
8
|
-
import type { DrizzleDatabase } from "../kernel/database/drizzle-db.js";
|
|
9
8
|
import * as authSchema from "./auth-schema.js";
|
|
10
9
|
|
|
11
10
|
type BetterAuthDbProvider = "pg" | "mysql" | "sqlite";
|
|
@@ -106,31 +105,9 @@ export function createAuth(
|
|
|
106
105
|
provider: resolveAuthDbProvider(db.provider),
|
|
107
106
|
schema: authSchema,
|
|
108
107
|
}),
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
after: async (user: { id: string; email?: string | null; name?: string | null }) => {
|
|
113
|
-
// Auto-create customer record on signup. Uses the Drizzle db
|
|
114
|
-
// directly because the kernel isn't fully initialized yet during
|
|
115
|
-
// auth setup. Best-effort — getByUserId() lazy-creates as fallback.
|
|
116
|
-
try {
|
|
117
|
-
const { customers } = await import("../kernel/database/schema.js");
|
|
118
|
-
const drizzle = db.db as DrizzleDatabase;
|
|
119
|
-
await drizzle.insert(customers).values({
|
|
120
|
-
organizationId: "org_default",
|
|
121
|
-
userId: user.id,
|
|
122
|
-
email: user.email ?? null,
|
|
123
|
-
firstName: user.name?.split(" ")[0] ?? null,
|
|
124
|
-
lastName: user.name?.split(" ").slice(1).join(" ") ?? null,
|
|
125
|
-
metadata: {},
|
|
126
|
-
}).onConflictDoNothing();
|
|
127
|
-
} catch {
|
|
128
|
-
// Silent — lazy creation in getByUserId() is the fallback
|
|
129
|
-
}
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
},
|
|
133
|
-
},
|
|
108
|
+
// Customer profile creation is handled lazily by CustomerService.getByUserId()
|
|
109
|
+
// which calls getOrCreateByUserId() on first access (checkout, /api/me/profile).
|
|
110
|
+
// No databaseHook needed — admins/staff who sign up don't need customer profiles.
|
|
134
111
|
trustedOrigins: config.auth?.trustedOrigins ?? [],
|
|
135
112
|
emailAndPassword: {
|
|
136
113
|
enabled: true,
|