Skip to content

Commit

Permalink
fix: user info empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerwin committed Mar 25, 2023
1 parent d2b04a6 commit 367dfd5
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
5 changes: 2 additions & 3 deletions service/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import express from 'express'
import jwt from 'jsonwebtoken'
import { ObjectId } from 'mongodb'
import type { RequestProps } from './types'
import type { ChatContext, ChatMessage } from './chatgpt'
import { chatConfig, chatReplyProcess, currentModel, initApi } from './chatgpt'
Expand Down Expand Up @@ -282,7 +281,7 @@ router.post('/user-register', async (req, res) => {

router.post('/config', auth, async (req, res) => {
try {
const userId = new ObjectId(req.headers.userId.toString())
const userId = req.headers.userId.toString()

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

const user = await getUserById(userId)
if (user == null || user.status !== Status.Normal)
Expand Down
3 changes: 1 addition & 2 deletions service/src/middleware/rootAuth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import jwt from 'jsonwebtoken'
import { ObjectId } from 'mongodb'
import { Status } from '../storage/model'
import { getUserById } from '../storage/mongo'
import { getCacheConfig } from '../storage/config'
Expand All @@ -11,7 +10,7 @@ const rootAuth = async (req, res, next) => {
const token = req.header('Authorization').replace('Bearer ', '')
const info = jwt.verify(token, config.siteConfig.loginSalt.trim())
req.headers.userId = info.userId
const user = await getUserById(new ObjectId(info.userId))
const user = await getUserById(info.userId)
if (user == null || user.status !== Status.Normal || user.email.toLowerCase() !== process.env.ROOT_USER)
res.send({ status: 'Fail', message: '无权限 | No permission.', data: null })
else
Expand Down
3 changes: 1 addition & 2 deletions src/store/modules/chat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,14 @@ export const useChatStore = defineStore('chat-store', {
uuid = r.uuid
this.chat.unshift({ uuid: r.uuid, data: [] })
if (uuid === r.uuid)
await this.syncChat(r, () => {})
this.syncChat(r, callback)
}
if (uuid == null) {
uuid = Date.now()
this.addHistory({ title: 'New Chat', uuid: Date.now(), isEdit: false })
}
this.active = uuid
this.reloadRoute(uuid)
callback && callback()
},

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

0 comments on commit 367dfd5

Please sign in to comment.