@lobehub/chat 1.36.4 → 1.36.5
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 1.36.5](https://github.com/lobehub/lobe-chat/compare/v1.36.4...v1.36.5)
|
6
|
+
|
7
|
+
<sup>Released on **2024-12-09**</sup>
|
8
|
+
|
9
|
+
#### 🐛 Bug Fixes
|
10
|
+
|
11
|
+
- **misc**: Fix wrong email linking in next-auth db adapter.
|
12
|
+
|
13
|
+
<br/>
|
14
|
+
|
15
|
+
<details>
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
17
|
+
|
18
|
+
#### What's fixed
|
19
|
+
|
20
|
+
- **misc**: Fix wrong email linking in next-auth db adapter, closes [#4919](https://github.com/lobehub/lobe-chat/issues/4919) ([af45a28](https://github.com/lobehub/lobe-chat/commit/af45a28))
|
21
|
+
|
22
|
+
</details>
|
23
|
+
|
24
|
+
<div align="right">
|
25
|
+
|
26
|
+
[](#readme-top)
|
27
|
+
|
28
|
+
</div>
|
29
|
+
|
5
30
|
### [Version 1.36.4](https://github.com/lobehub/lobe-chat/compare/v1.36.3...v1.36.4)
|
6
31
|
|
7
32
|
<sup>Released on **2024-12-09**</sup>
|
package/changelog/v1.json
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@lobehub/chat",
|
3
|
-
"version": "1.36.
|
3
|
+
"version": "1.36.5",
|
4
4
|
"description": "Lobe Chat - an open-source, high-performance chatbot 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",
|
@@ -115,6 +115,37 @@ describe('LobeNextAuthDbAdapter', () => {
|
|
115
115
|
await serverDB.query.users.findMany({ where: eq(users.email, user.email) }),
|
116
116
|
).toHaveLength(1);
|
117
117
|
});
|
118
|
+
|
119
|
+
it('should create a user if id not exist and email is null', async () => {
|
120
|
+
// In previous version, it will link the account to the existing user if the email is null
|
121
|
+
// issue: https://github.com/lobehub/lobe-chat/issues/4918
|
122
|
+
expect(nextAuthAdapter).toBeDefined();
|
123
|
+
expect(nextAuthAdapter.createUser).toBeDefined();
|
124
|
+
|
125
|
+
const existUserId = 'user-db-1';
|
126
|
+
const existUserName = 'John Doe 1';
|
127
|
+
// @ts-expect-error: createUser is defined
|
128
|
+
await nextAuthAdapter.createUser({
|
129
|
+
...user,
|
130
|
+
id: existUserId,
|
131
|
+
name: existUserName,
|
132
|
+
email: '',
|
133
|
+
});
|
134
|
+
|
135
|
+
const anotherUserId = 'user-db-2';
|
136
|
+
const anotherUserName = 'John Doe 2';
|
137
|
+
// @ts-expect-error: createUser is defined
|
138
|
+
await nextAuthAdapter.createUser({
|
139
|
+
...user,
|
140
|
+
id: anotherUserId,
|
141
|
+
name: anotherUserName,
|
142
|
+
email: '',
|
143
|
+
});
|
144
|
+
// Should create a new user if id not exists and email is null
|
145
|
+
expect(
|
146
|
+
await serverDB.query.users.findMany({ where: eq(users.id, anotherUserId) }),
|
147
|
+
).toHaveLength(1);
|
148
|
+
});
|
118
149
|
});
|
119
150
|
|
120
151
|
describe('deleteUser', () => {
|
@@ -8,8 +8,8 @@ import { and, eq } from 'drizzle-orm';
|
|
8
8
|
import type { NeonDatabase } from 'drizzle-orm/neon-serverless';
|
9
9
|
import { Adapter, AdapterAccount } from 'next-auth/adapters';
|
10
10
|
|
11
|
-
import { UserModel } from '@/database/server/models/user';
|
12
11
|
import * as schema from '@/database/schemas';
|
12
|
+
import { UserModel } from '@/database/server/models/user';
|
13
13
|
import { merge } from '@/utils/merge';
|
14
14
|
|
15
15
|
import {
|
@@ -53,7 +53,7 @@ export function LobeNextAuthDbAdapter(serverDB: NeonDatabase<typeof schema>): Ad
|
|
53
53
|
async createUser(user): Promise<AdapterUser> {
|
54
54
|
const { id, name, email, emailVerified, image, providerAccountId } = user;
|
55
55
|
// return the user if it already exists
|
56
|
-
let existingUser = await UserModel.findByEmail(serverDB, email);
|
56
|
+
let existingUser = email.trim() ? await UserModel.findByEmail(serverDB, email) : undefined;
|
57
57
|
// If the user is not found by email, try to find by providerAccountId
|
58
58
|
if (!existingUser && providerAccountId) {
|
59
59
|
existingUser = await UserModel.findById(serverDB, providerAccountId);
|
@@ -169,7 +169,7 @@ export function LobeNextAuthDbAdapter(serverDB: NeonDatabase<typeof schema>): Ad
|
|
169
169
|
},
|
170
170
|
|
171
171
|
async getUserByEmail(email): Promise<AdapterUser | null> {
|
172
|
-
const lobeUser = await UserModel.findByEmail(serverDB, email);
|
172
|
+
const lobeUser = email.trim() ? await UserModel.findByEmail(serverDB, email) : undefined;
|
173
173
|
return lobeUser ? mapLobeUserToAdapterUser(lobeUser) : null;
|
174
174
|
},
|
175
175
|
|