Fix type mismatch in removeChat function
This commit is contained in:
parent
35e83dc87e
commit
df02a18d8c
1 changed files with 5 additions and 1 deletions
|
|
@ -51,7 +51,11 @@ export async function removeChat({ id, path }: { id: string; path: string }) {
|
||||||
|
|
||||||
const uid = await kv.hget<string>(`chat:${id}`, 'userId')
|
const uid = await kv.hget<string>(`chat:${id}`, 'userId')
|
||||||
|
|
||||||
if (uid !== session?.user?.id) {
|
// Convert both IDs to strings before comparing
|
||||||
|
// This is necessary because the session user ID is a string, while the chat user ID is a number
|
||||||
|
// The strict inequality check (!==) in JavaScript checks both value and type, so it would fail if the types are different
|
||||||
|
// By converting both IDs to strings, we ensure that the comparison is done between two strings, and it will work correctly even if the IDs are originally of different types
|
||||||
|
if (String(uid) !== String(session?.user?.id)) {
|
||||||
return {
|
return {
|
||||||
error: 'Unauthorized'
|
error: 'Unauthorized'
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue