perf: 优化部份判断

This commit is contained in:
ChenZhaoYu
2023-03-17 08:57:27 +08:00
parent b3cfe7a976
commit 2ad7567548
5 changed files with 63 additions and 45 deletions

View File

@@ -1,6 +1,8 @@
import { isNotEmptyString } from '../utils/is'
const auth = async (req, res, next) => {
const AUTH_SECRET_KEY = process.env.AUTH_SECRET_KEY
if (typeof AUTH_SECRET_KEY === 'string' && AUTH_SECRET_KEY.length > 0) {
if (isNotEmptyString(AUTH_SECRET_KEY)) {
try {
const Authorization = req.header('Authorization')
if (!Authorization || Authorization.replace('Bearer ', '').trim() !== AUTH_SECRET_KEY.trim())