修正未登录情况下, 无法获取游戏内任务列表的bug
This commit is contained in:
parent
2c4521f831
commit
9ac2b197f8
@ -31,6 +31,16 @@ const apiAuthPlugin: FastifyPluginAsync<ApiAuthOptions> = async function (fastif
|
|||||||
})
|
})
|
||||||
// 只有路由配置的role为anon才不需要过滤
|
// 只有路由配置的role为anon才不需要过滤
|
||||||
fastify.decorate('apiAuth', async function (request: FastifyRequest, reply: FastifyReply) {
|
fastify.decorate('apiAuth', async function (request: FastifyRequest, reply: FastifyReply) {
|
||||||
|
let activity = new ReadOnlyCache().getData(ACTIVITY_NAME)
|
||||||
|
if (!activity) {
|
||||||
|
activity = await ActivityInfo.findById(ACTIVITY_NAME)
|
||||||
|
if (activity) {
|
||||||
|
new ReadOnlyCache().setData(ACTIVITY_NAME, activity)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (activity) {
|
||||||
|
request.activity = activity
|
||||||
|
}
|
||||||
if (!request.roles || request.roles.indexOf(ROLE_ANON) == -1 || request.token) {
|
if (!request.roles || request.roles.indexOf(ROLE_ANON) == -1 || request.token) {
|
||||||
try {
|
try {
|
||||||
if (!request.token) {
|
if (!request.token) {
|
||||||
@ -46,16 +56,6 @@ const apiAuthPlugin: FastifyPluginAsync<ApiAuthOptions> = async function (fastif
|
|||||||
return reply.send({ errcode: 10, errmsg: 'need login' })
|
return reply.send({ errcode: 10, errmsg: 'need login' })
|
||||||
}
|
}
|
||||||
request.user = account
|
request.user = account
|
||||||
let activity = new ReadOnlyCache().getData(ACTIVITY_NAME)
|
|
||||||
if (!activity) {
|
|
||||||
activity = await ActivityInfo.findById(ACTIVITY_NAME)
|
|
||||||
if (activity) {
|
|
||||||
new ReadOnlyCache().setData(ACTIVITY_NAME, activity)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (activity) {
|
|
||||||
request.activity = activity
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return reply.send({ errcode: 401, errmsg: 'need auth' })
|
return reply.send({ errcode: 401, errmsg: 'need auth' })
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user