flexbiz-server
Version:
Flexible Server
4 lines (3 loc) • 975 B
JavaScript
const passport=require("passport");
module.exports=function($req$$,$res$$,$next$$){passport.authenticate("bearer",{session:!1},function($err_errorMatch_errorMessage$$,$match_user$$,$info$$){if($err_errorMatch_errorMessage$$)return $res$$.status(500).json({error:$err_errorMatch_errorMessage$$.message||$err_errorMatch_errorMessage$$||"Internal Server Error",code:500});if(!$match_user$$)return $err_errorMatch_errorMessage$$="Unauthorized",typeof $info$$==="string"?($match_user$$=$info$$.match(/error_description="([^"]+)"/))&&$match_user$$[1]?
$err_errorMatch_errorMessage$$=$match_user$$[1]:$info$$.includes('error="')&&($err_errorMatch_errorMessage$$=($err_errorMatch_errorMessage$$=$info$$.match(/error="([^"]+)"/))?$err_errorMatch_errorMessage$$[1]:$info$$):$info$$&&$info$$.message&&($err_errorMatch_errorMessage$$=$info$$.message),$res$$.status(401).json({error:$err_errorMatch_errorMessage$$,code:401});$req$$.user=$match_user$$;$next$$()})($req$$,$res$$,$next$$)};