@lobehub/lobehub 2.0.0-next.154 โ†’ 2.0.0-next.155

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/CHANGELOG.md CHANGED
@@ -2,6 +2,31 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ## [Version 2.0.0-next.155](https://github.com/lobehub/lobe-chat/compare/v2.0.0-next.154...v2.0.0-next.155)
6
+
7
+ <sup>Released on **2025-12-03**</sup>
8
+
9
+ #### ๐Ÿ› Bug Fixes
10
+
11
+ - **misc**: Missing init user after user creation.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### What's fixed
19
+
20
+ - **misc**: Missing init user after user creation, closes [#10587](https://github.com/lobehub/lobe-chat/issues/10587) ([0e97a42](https://github.com/lobehub/lobe-chat/commit/0e97a42))
21
+
22
+ </details>
23
+
24
+ <div align="right">
25
+
26
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
27
+
28
+ </div>
29
+
5
30
  ## [Version 2.0.0-next.154](https://github.com/lobehub/lobe-chat/compare/v2.0.0-next.153...v2.0.0-next.154)
6
31
 
7
32
  <sup>Released on **2025-12-03**</sup>
package/changelog/v1.json CHANGED
@@ -1,4 +1,13 @@
1
1
  [
2
+ {
3
+ "children": {
4
+ "fixes": [
5
+ "Missing init user after user creation."
6
+ ]
7
+ },
8
+ "date": "2025-12-03",
9
+ "version": "2.0.0-next.155"
10
+ },
2
11
  {
3
12
  "children": {
4
13
  "fixes": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/lobehub",
3
- "version": "2.0.0-next.154",
3
+ "version": "2.0.0-next.155",
4
4
  "description": "LobeHub - an open-source,comprehensive AI Agent framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.",
5
5
  "keywords": [
6
6
  "framework",
@@ -4,9 +4,9 @@ export interface PythonOptions {
4
4
  */
5
5
  pyodideIndexUrl?: string;
6
6
  /**
7
- * PyPI ็ดขๅผ• URL๏ผŒ่ฆๆฑ‚ๆ”ฏๆŒ [JSON API](https://warehouse.pypa.io/api-reference/json.html)
7
+ * PyPI index URL, must support [JSON API](https://warehouse.pypa.io/api-reference/json.html)
8
8
  *
9
- * ้ป˜่ฎคๅ€ผ๏ผš`https://pypi.org/pypi/{package_name}/json`
9
+ * Default value: `https://pypi.org/pypi/{package_name}/json`
10
10
  */
11
11
  pypiIndexUrl?: string;
12
12
  }
package/src/auth.ts CHANGED
@@ -13,6 +13,7 @@ import {
13
13
  import { initBetterAuthSSOProviders } from '@/libs/better-auth/sso';
14
14
  import { parseSSOProviders } from '@/libs/better-auth/utils/server';
15
15
  import { EmailService } from '@/server/services/email';
16
+ import { UserService } from '@/server/services/user';
16
17
 
17
18
  // Email verification link expiration time (in seconds)
18
19
  // Default is 1 hour (3600 seconds) as per Better Auth documentation
@@ -120,6 +121,26 @@ export const auth = betterAuth({
120
121
  database: drizzleAdapter(serverDB, {
121
122
  provider: 'pg',
122
123
  }),
124
+ /**
125
+ * Run user bootstrap for every newly created account (email, magic link, OAuth/social, etc.).
126
+ * Using Better Auth database hooks ensures we catch social flows that bypass /sign-up/* routes.
127
+ * Ref: https://www.better-auth.com/docs/reference/options#databasehooks
128
+ */
129
+ databaseHooks: {
130
+ user: {
131
+ create: {
132
+ after: async (user) => {
133
+ const userService = new UserService(serverDB);
134
+ await userService.initUser({
135
+ email: user.email,
136
+ id: user.id,
137
+ username: user.username as string | null,
138
+ // TODO: if add phone plugin, we should fill phone here
139
+ });
140
+ },
141
+ },
142
+ },
143
+ },
123
144
  user: {
124
145
  additionalFields: {
125
146
  username: {
@@ -8,6 +8,15 @@ import { KeyVaultsGateKeeper } from '@/server/modules/KeyVaultsEncrypt';
8
8
  import { S3 } from '@/server/modules/S3';
9
9
  import { AgentService } from '@/server/services/agent';
10
10
 
11
+ type CreatedUser = {
12
+ email?: string | null;
13
+ firstName?: string | null;
14
+ id: string;
15
+ lastName?: string | null;
16
+ phone?: string | null;
17
+ username?: string | null;
18
+ };
19
+
11
20
  export class UserService {
12
21
  private db: LobeChatDatabase;
13
22
 
@@ -15,6 +24,30 @@ export class UserService {
15
24
  this.db = db;
16
25
  }
17
26
 
27
+ async initUser(user: CreatedUser) {
28
+ const agentService = new AgentService(this.db, user.id);
29
+ await agentService.createInbox();
30
+
31
+ /* โ†“ cloud slot โ†“ */
32
+ /* โ†‘ cloud slot โ†‘ */
33
+
34
+ const analytics = await initializeServerAnalytics();
35
+ analytics?.identify(user.id, {
36
+ email: user.email ?? undefined,
37
+ firstName: user.firstName ?? undefined,
38
+ lastName: user.lastName ?? undefined,
39
+ phone: user.phone ?? undefined,
40
+ username: user.username ?? undefined,
41
+ });
42
+ analytics?.track({
43
+ name: 'user_register_completed',
44
+ properties: {
45
+ spm: 'user_service.init_user.user_created',
46
+ },
47
+ userId: user.id,
48
+ });
49
+ }
50
+
18
51
  createUser = async (id: string, params: UserJSON) => {
19
52
  // Check if user already exists
20
53
  const res = await UserModel.findById(this.db, id);
@@ -34,10 +67,6 @@ export class UserService {
34
67
  return index === 0;
35
68
  });
36
69
 
37
- /* โ†“ cloud slot โ†“ */
38
-
39
- /* โ†‘ cloud slot โ†‘ */
40
-
41
70
  // 2. create user in database
42
71
  await UserModel.createUser(this.db, {
43
72
  avatar: params.image_url,
@@ -50,30 +79,14 @@ export class UserService {
50
79
  username: params.username,
51
80
  });
52
81
 
53
- // 3. Create an inbox session for the user
54
- const agentService = new AgentService(this.db, id);
55
- await agentService.createInbox();
56
-
57
- /* โ†“ cloud slot โ†“ */
58
-
59
- /* โ†‘ cloud slot โ†‘ */
60
-
61
- //analytics
62
- const analytics = await initializeServerAnalytics();
63
- analytics?.identify(id, {
82
+ await this.initUser({
64
83
  email: email?.email_address,
65
84
  firstName: params.first_name,
85
+ id,
66
86
  lastName: params.last_name,
67
87
  phone: phone?.phone_number,
68
88
  username: params.username,
69
89
  });
70
- analytics?.track({
71
- name: 'user_register_completed',
72
- properties: {
73
- spm: 'user_service.create_user.user_created',
74
- },
75
- userId: id,
76
- });
77
90
 
78
91
  return { message: 'user created', success: true };
79
92
  };