Skip to content

Commit

Permalink
v2.20.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Dooy committed Aug 25, 2024
1 parent fe8e51f commit 35b7019
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion api/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = (req, res) => {
"message": "密钥无效 | Secret key is invalid",
"data": null
};
const auth_secret_keys = process.env.AUTH_SECRET_KEY.trim().split(',').filter(item => item !== '');
const auth_secret_keys = process.env.AUTH_SECRET_KEY? process.env.AUTH_SECRET_KEY.trim().split(',').filter(item => item !== ''):[];
if (req.body && req.body.token && auth_secret_keys.include(req.body.token)) obj = {
status: 'Success',
message: 'Verify successfully',
Expand Down
8 changes: 5 additions & 3 deletions service/src/middleware/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const verify= async ( req :Request , res:Response ) => {
if (!token)
throw new Error('Secret key is empty')

const auth_secret_keys = process.env.AUTH_SECRET_KEY.trim().split(',').filter(item => item !== '');
const auth_secret_keys = process.env.AUTH_SECRET_KEY? process.env.AUTH_SECRET_KEY.trim().split(',').filter(item => item !== ''):[];
if (!auth_secret_keys.includes(token))
throw new Error('密钥无效 | Secret key is invalid')
clearLimit( req, res);
Expand All @@ -49,7 +49,8 @@ export const auth = async ( req :Request , res:Response , next:NextFunction ) =>
try {
checkLimit( req, res );
const Authorization = req.header('Authorization')
const auth_secret_keys = process.env.AUTH_SECRET_KEY.trim().split(',').filter(item => item !== '');
//const auth_secret_keys = process.env.AUTH_SECRET_KEY.trim().split(',').filter(item => item !== '');
const auth_secret_keys = process.env.AUTH_SECRET_KEY? process.env.AUTH_SECRET_KEY.trim().split(',').filter(item => item !== ''):[];
if (!Authorization || !auth_secret_keys.includes(Authorization.replace('Bearer ', '').trim()))
throw new Error('Error: 无访问权限 | No access rights')

Expand Down Expand Up @@ -104,7 +105,8 @@ const clearLimit= ( req :Request , res:Response )=>{
export const authV2 = async ( req :Request , res:Response , next:NextFunction ) => {

const AUTH_SECRET_KEY = process.env.AUTH_SECRET_KEY
const auth_secret_keys = AUTH_SECRET_KEY.trim().split(',').filter(item => item !== '');
//const auth_secret_keys = AUTH_SECRET_KEY.trim().split(',').filter(item => item !== '');
const auth_secret_keys = process.env.AUTH_SECRET_KEY? process.env.AUTH_SECRET_KEY.trim().split(',').filter(item => item !== ''):[];
if (isNotEmptyString(AUTH_SECRET_KEY)) {
try {

Expand Down

0 comments on commit 35b7019

Please sign in to comment.