@contentgrowth/content-auth 0.5.3 → 0.5.4
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/backend/index.d.ts
CHANGED
|
@@ -879,6 +879,16 @@ interface AuthConfig {
|
|
|
879
879
|
* If not provided, uses default table names (users, sessions, accounts, etc.).
|
|
880
880
|
*/
|
|
881
881
|
schemaMapping?: SchemaMapping;
|
|
882
|
+
/**
|
|
883
|
+
* Callback triggered when a new user signs up.
|
|
884
|
+
* This includes email signups and OAuth signups (first time).
|
|
885
|
+
*/
|
|
886
|
+
onSignup?: (user: any) => Promise<void> | void;
|
|
887
|
+
/**
|
|
888
|
+
* Callback triggered when a user signs in.
|
|
889
|
+
* This triggers on every successful session creation (including signup).
|
|
890
|
+
*/
|
|
891
|
+
onSignin?: (user: any) => Promise<void> | void;
|
|
882
892
|
[key: string]: any;
|
|
883
893
|
}
|
|
884
894
|
declare const createAuth: (config: AuthConfig) => better_auth.Auth<any>;
|
package/dist/backend/index.js
CHANGED
|
@@ -366,6 +366,8 @@ var createAuth = (config) => {
|
|
|
366
366
|
turnstile: turnstileConfig,
|
|
367
367
|
emailNormalization,
|
|
368
368
|
signInTracking,
|
|
369
|
+
onSignup,
|
|
370
|
+
onSignin,
|
|
369
371
|
schemaMapping,
|
|
370
372
|
user,
|
|
371
373
|
session,
|
|
@@ -485,15 +487,53 @@ var createAuth = (config) => {
|
|
|
485
487
|
after: async (context) => {
|
|
486
488
|
const path = context.path || "";
|
|
487
489
|
const user2 = context.user || context.response?.user || context.data?.user || context.context?.returned?.user || context.context?.newSession?.user;
|
|
488
|
-
if (
|
|
489
|
-
if (
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
490
|
+
if (user2) {
|
|
491
|
+
if (emailNormalization?.enabled && rawDb?.prepare) {
|
|
492
|
+
if ((path.includes("/sign-up") || path.includes("/callback")) && user2.id && user2.email) {
|
|
493
|
+
try {
|
|
494
|
+
const normalized = normalizeEmail(user2.email);
|
|
495
|
+
await rawDb.prepare(
|
|
496
|
+
`UPDATE ${userTableName} SET ${normalizedEmailColumn} = ? WHERE ${userIdColumn} = ? AND (${normalizedEmailColumn} IS NULL OR ${normalizedEmailColumn} != ?)`
|
|
497
|
+
).bind(normalized, user2.id, normalized).run();
|
|
498
|
+
} catch (e) {
|
|
499
|
+
console.error(`[ContentAuth] Failed to set normalized_email: ${e.message}`);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
if (onSignup) {
|
|
504
|
+
let isNewUser = false;
|
|
505
|
+
if (path.includes("/sign-up/email")) {
|
|
506
|
+
isNewUser = true;
|
|
507
|
+
} else if (path.includes("/callback")) {
|
|
508
|
+
if (user2.createdAt) {
|
|
509
|
+
const createdAt = new Date(user2.createdAt).getTime();
|
|
510
|
+
const now = Date.now();
|
|
511
|
+
if (now - createdAt < 1e4) {
|
|
512
|
+
isNewUser = true;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
if (isNewUser) {
|
|
517
|
+
try {
|
|
518
|
+
const result = onSignup(user2);
|
|
519
|
+
if (result instanceof Promise) {
|
|
520
|
+
result.catch((e) => console.error(`[ContentAuth] onSignup hook failed: ${e.message}`));
|
|
521
|
+
}
|
|
522
|
+
} catch (e) {
|
|
523
|
+
console.error(`[ContentAuth] onSignup hook failed: ${e.message}`);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
if (onSignin) {
|
|
528
|
+
if (path.includes("/sign-in") || path.includes("/sign-up") || path.includes("/callback")) {
|
|
529
|
+
try {
|
|
530
|
+
const result = onSignin(user2);
|
|
531
|
+
if (result instanceof Promise) {
|
|
532
|
+
result.catch((e) => console.error(`[ContentAuth] onSignin hook failed: ${e.message}`));
|
|
533
|
+
}
|
|
534
|
+
} catch (e) {
|
|
535
|
+
console.error(`[ContentAuth] onSignin hook failed: ${e.message}`);
|
|
536
|
+
}
|
|
497
537
|
}
|
|
498
538
|
}
|
|
499
539
|
}
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentgrowth/content-auth",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"description": "Better Auth wrapper with UI components for Cloudflare Workers & Pages. Includes custom schema mapping, Turnstile bot protection, and email normalization.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|