diff --git a/app/io/controller/chat.ts b/app/io/controller/chat.ts index dda154a..2158fb0 100644 --- a/app/io/controller/chat.ts +++ b/app/io/controller/chat.ts @@ -186,7 +186,7 @@ module.exports = (app: Application) => { request_time: new Date().valueOf(), state: 1, }; - // TODO: 不能重复发送好友请求 + // TODO: 不能重复发送好友请求( 目前使用逐渐验证 ) await ctx.service.userFriend.create(user_friend); this.notify(to, 'receive_friend_request', from); diff --git a/app/io/middleware/auth.ts b/app/io/middleware/auth.ts index abf12b5..e54ac77 100644 --- a/app/io/middleware/auth.ts +++ b/app/io/middleware/auth.ts @@ -6,8 +6,14 @@ import { Application, Context } from 'egg'; module.exports = (app: Application) => { return async function(ctx: Context, next) { - ctx.logger.info('auth!'); - await next; + const token = ctx.socket.handshake.query.token; + const reply = await app['redis'].get(token); + if (reply) { + app['redis'].expire(token, 3 * 24 * 60 * 60); + await next; + } else { + ctx.socket.disconnect(); + } ctx.logger.info('disconnect!'); }; };