Skip to content

Commit 704c7c8

Browse files
authored
🐛 fix: next-auth user id not found in create agent index (lobehub#6410)
1 parent 5aa59c0 commit 704c7c8

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/libs/next-auth/adapter/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,26 @@ export function LobeNextAuthDbAdapter(serverDB: NeonDatabase<typeof schema>): Ad
6868
}
6969

7070
// create a new user if it does not exist
71+
// Use id from provider if it exists, otherwise use id assigned by next-auth
72+
// ref: https://github.com/lobehub/lobe-chat/pull/2935
73+
const uid = providerAccountId ?? id;
7174
await UserModel.createUser(
7275
serverDB,
7376
mapAdapterUserToLobeUser({
7477
email,
7578
emailVerified,
7679
// Use providerAccountId as userid to identify if the user exists in a SSO provider
77-
id: providerAccountId ?? id,
80+
id: uid,
7881
image,
7982
name,
8083
}),
8184
);
8285

8386
// 3. Create an inbox session for the user
84-
const agentService = new AgentService(serverDB, id);
87+
const agentService = new AgentService(serverDB, uid);
8588
await agentService.createInbox();
8689

87-
return { ...user, id: providerAccountId ?? id };
90+
return { ...user, id: uid };
8891
},
8992
async createVerificationToken(data): Promise<VerificationToken | null | undefined> {
9093
return serverDB

0 commit comments

Comments
 (0)