Skip to content

Commit 367dfd5

Browse files
author
Kerwin
committed
fix: user info empty
1 parent d2b04a6 commit 367dfd5

File tree

3 files changed

+4
-7
lines changed

3 files changed

+4
-7
lines changed

service/src/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import express from 'express'
22
import jwt from 'jsonwebtoken'
3-
import { ObjectId } from 'mongodb'
43
import type { RequestProps } from './types'
54
import type { ChatContext, ChatMessage } from './chatgpt'
65
import { chatConfig, chatReplyProcess, currentModel, initApi } from './chatgpt'
@@ -282,7 +281,7 @@ router.post('/user-register', async (req, res) => {
282281

283282
router.post('/config', auth, async (req, res) => {
284283
try {
285-
const userId = new ObjectId(req.headers.userId.toString())
284+
const userId = req.headers.userId.toString()
286285

287286
const user = await getUserById(userId)
288287
if (user == null || user.status !== Status.Normal || user.email.toLowerCase() !== process.env.ROOT_USER)
@@ -340,7 +339,7 @@ router.post('/user-login', async (req, res) => {
340339
router.post('/user-info', auth, async (req, res) => {
341340
try {
342341
const { name, avatar, description } = req.body as UserInfo
343-
const userId = new ObjectId(req.headers.userId.toString())
342+
const userId = req.headers.userId.toString()
344343

345344
const user = await getUserById(userId)
346345
if (user == null || user.status !== Status.Normal)

service/src/middleware/rootAuth.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import jwt from 'jsonwebtoken'
2-
import { ObjectId } from 'mongodb'
32
import { Status } from '../storage/model'
43
import { getUserById } from '../storage/mongo'
54
import { getCacheConfig } from '../storage/config'
@@ -11,7 +10,7 @@ const rootAuth = async (req, res, next) => {
1110
const token = req.header('Authorization').replace('Bearer ', '')
1211
const info = jwt.verify(token, config.siteConfig.loginSalt.trim())
1312
req.headers.userId = info.userId
14-
const user = await getUserById(new ObjectId(info.userId))
13+
const user = await getUserById(info.userId)
1514
if (user == null || user.status !== Status.Normal || user.email.toLowerCase() !== process.env.ROOT_USER)
1615
res.send({ status: 'Fail', message: '无权限 | No permission.', data: null })
1716
else

src/store/modules/chat/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,14 @@ export const useChatStore = defineStore('chat-store', {
3838
uuid = r.uuid
3939
this.chat.unshift({ uuid: r.uuid, data: [] })
4040
if (uuid === r.uuid)
41-
await this.syncChat(r, () => {})
41+
this.syncChat(r, callback)
4242
}
4343
if (uuid == null) {
4444
uuid = Date.now()
4545
this.addHistory({ title: 'New Chat', uuid: Date.now(), isEdit: false })
4646
}
4747
this.active = uuid
4848
this.reloadRoute(uuid)
49-
callback && callback()
5049
},
5150

5251
async syncChat(h: Chat.History, callback: () => void) {

0 commit comments

Comments
 (0)