beta
This commit is contained in:
		
							
								
								
									
										17
									
								
								nodejs/middleware/auth.js
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										17
									
								
								nodejs/middleware/auth.js
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,17 @@ | ||||
| 'use strict'; | ||||
|  | ||||
| const {Auth} = require('../models/auth');  | ||||
|  | ||||
| async function auth(req, res, next){ | ||||
| 	try{ | ||||
| 		let user = await Auth.checkToken({token: req.header('auth-token')}); | ||||
| 		if(user.username){ | ||||
| 			req.user = user; | ||||
| 			return next(); | ||||
| 		} | ||||
| 	}catch(error){ | ||||
| 		next(error); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| module.exports = {auth}; | ||||
		Reference in New Issue
	
	Block a user