Authorization url
Server side url
const authenticate = async (req, res, next) => {
const token = req.get("Authorization");
const auth = new Promise(async (resolve, reject)=> {
axios.post(`${auth_url}`, {
access_token: token,
},
{
headers: {
'app_secret': `${app_secret}`
}
}
)
.then((response)=> {
resolve(response.data);
})
.catch(()=> {
reject();
})
auth.then((usercred)=> {
// storing the user credentials for rest of the request lifecycle
res.locals.uid = usercred.data.uid
res.locals.email = usercred.data.email
// getting control flow to request route
next()
})
.catch(()=> {
res.status(403).json({
result: "You are not authorized to access this resource",
success: false
})
})
}Last updated