在运行时检测 my.envar || wo.envar,防止被提前引用导致 my.envar 为空
This commit is contained in:
		
							parent
							
								
									b69c154255
								
							
						
					
					
						commit
						16026ac48e
					
				| @ -2,13 +2,13 @@ const JsonWebToken = require('jsonwebtoken') | ||||
| 
 | ||||
| const crypto = require('crypto') | ||||
| 
 | ||||
| const my = { envar: typeof wo !== 'undefined' ? wo.envar : globalThis.envar || {} } | ||||
| const my = {} // 不要在这里 `my = { envar: wo?.envar || globalThis.envar || {} }`,危险!其他类里如提前引用,可能导致 my.envar 一直是空的
 | ||||
| 
 | ||||
| module.exports = { | ||||
|   init (envar) { | ||||
|   initMy (envar) { | ||||
|     my.envar = envar | ||||
|   }, | ||||
|   createToken (content, key = my.envar.tokenKey) { | ||||
|   createToken (content, key = my.envar?.tokenKey || wo?.envar?.tokenKey) { | ||||
|     if (!key) { | ||||
|       console.warn('*** tokenkey is empty! ***') | ||||
|     } | ||||
| @ -26,7 +26,7 @@ module.exports = { | ||||
|       return null | ||||
|     } | ||||
|   }, | ||||
|   verifyToken (token, key = my.envar.tokenKey) { | ||||
|   verifyToken (token, key = my.envar.tokenKey || wo?.envar?.tokenKey) { | ||||
|     if (!key) { | ||||
|       console.warn('*** tokenkey is empty! ***') | ||||
|     } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user