utils/api.js
//actionFn is a function that we are passing in, so basically a function passing in a function to get use
actionFn is a function that we are passing in, so basically a function passing in a function to get use
actionFn is a function that we are passing in so basically a function passing in a function to get use
function authenticatedAction(actionFn) {
  return auth0.requireAuthentication(async function (req, res) {
    try {
      const { user } = await auth0.getSession(req);
      const actionResult = await actionFn(req, user);
      res.statusCode = actionResult ? 200 : 204;
      res.end(JSON.stringify(actionResult)); 
    } catch (error) {
      console.error(error); 
      res
        .status(error.status || 500) 
        .end(error.message && JSON.stringify({ message: error.message }));
    }
  });
}
function authenticatedAction ( actionFn ) { return auth0 . requireAuthentication ( async function ( req , res ) { try { const { user } = await auth0 . getSession ( req ) ; const actionResult = await actionFn ( req , user ) ; res . statusCode = actionResult ? 200 : 204 ; res . end ( JSON . stringify ( actionResult ) ) ; } catch ( error ) { console . error ( error ) ; res . status ( error . status || 500 ) . end ( error . message && JSON . stringify ( { message : error . message } ) ) ; } } ) ; }
actionFn is a function that we are passing in, so basically a function passing in a function to get use
actionFn is a function that we are passing in so basically a function passing in a function to get use
//auth0 is an object client that has the function requireAuthentication() <- we are passing in the paramter another function x // We need auth0 authentication just so that we can get a session (getSession()) //requireAuthentication redirects you to the authentication pagevvddddd //If anything we have done so far failed, then we would jump out the function and run the catch block //Then we use the getSession to extra the user object // await attachUserMetadata(user); // Here the function passed into actionFn is getting used and actual results is // the object that gest passed back here // returns the respond object with what the actionResult has //Tells the backend log what is the error // Returns the error status message or 500