Spaces:
				
			
			
	
			
			
		Build error
		
	
	
	
			
			
	
	
	
	
		
		
		Build error
		
	| 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) { | |
| try { | |
| const Authorization = req.header('Authorization') | |
| if (!Authorization || Authorization.replace('Bearer ', '').trim() !== AUTH_SECRET_KEY.trim()) | |
| throw new Error('Error: ๆ ่ฎฟ้ฎๆ้ | No access rights') | |
| next() | |
| } | |
| catch (error) { | |
| res.send({ status: 'Unauthorized', message: error.message ?? 'Please authenticate.', data: null }) | |
| } | |
| } | |
| else { | |
| next() | |
| } | |
| } | |
| export { auth } | |