``There is an issue with getServerSideProps when wrapping it in a

When attempting to implement an auth handler function around getServersideProps, I encountered the following error message:

TypeError: getServerSideProps is not a function
The wrapper code in question is as follows:

export async function protect(gssp) {
    return async (context) => {
        const {req, res} = context;
        const auth = await authHandler(req);
        if (!auth.authenticated) {
            res.statusCode = 302;
            res.setHeader('Location', '/');
            return;
        }
        context.auth = auth;
        return await gssp(context);
    }
}

The implementation of getServerSideProps on the page appears like this:

export const getServerSideProps = protect(async function(context) {
    return {
        props: {
            auth: context.auth
        }
    }
})

Answer №1

When you use the protect(...) function, it will return a promise instead of a regular function because you have defined it with the keyword async. To resolve this problem, all you need to do is remove the async keyword from the function.

export function protect(gssp) {
    // No changes made here
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Use angular js to dynamically load a template via an ajax request

I am trying to send an AJAX request in order to retrieve a JSP/HTML page for the templateUrl of a modal. Here is the code I have written: var modalInstance = $uibModal.open({ animation: $scope.animationsEnabled, te ...

The process of reversing an array is not fully completing due to the pop method being used within a loop

Note: I've been immersed in code for hours now and have reached a stage where I'm starting to doubt the spelling of every word or question if I have dyslexia. Despite this, I know this should be a simple question. I want to create a basic functi ...

Set YouTube Playlist to start from a random index when embedded

I've been trying to figure out how to set my embedded playlist to start with a random video. Here's what I attempted: <iframe src="https://www.youtube.com/embed/videoseries?list=PLPmj00V6sF0s0k3Homcg1jkP0mLjddPgJ&index=<?php print(ran ...

jQuery - easily adjust wrapping and unwrapping elements for responsive design. Perfect for quickly undo

Within the WordPress PHP permalinks and Fancybox plugin, there are elements enclosed in an "a" tag like so: <a href="<?php the_permalink(); ?>" class="example" id="exampleid" data-fancybox-type="iframe"> <div class="exampledivclass"> ...

Organizing requests in PHP: What are the best methods?

My attempt to use the code below for queuing requests has not produced the desired results! <?php $Sleep_Time = "10"; if (isset($_POST["String"])){ $File = "Edit_File_Content.txt"; while(file_exists($File . "_L ...

Resizing an image within an anchor tag

Currently, I am working on styling a page in NextJS. The challenge I'm facing is resizing an image that is inside an anchor within a div. Despite numerous attempts, the image refuses to resize as desired. I've experimented with applying properti ...

Deploy the Next.js app on Vercel without regenerating pages, and instead trigger the deployment only upon request

Greetings to my fellow developers, For the past year, I have been using Next.js on Vercel and so far, I am absolutely loving it. The ability to create SEO friendly React websites has been a game changer for me. However, as my website continues to grow and ...

What causes parameters to be initially passed as undefined when sending them from one component to another, only to later arrive with the actual data intact

When passing properties from a parent component to a child component, my code gets executed before the properties arrive. This results in an error stating "Cannot read properties of undefined (reading 'map')". Why does this occur? https://i.ssta ...

Issues of unfulfilled requirements in the recent npm (and node) updates

After updating npm and node to the latest versions, I am encountering the following errors and warnings: $ npm --version 2.4.1 $ node --version v0.10.36 $ npm install > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f895 ...

Issue encountered when attempting to send FormData from Next.js API to Express.js backend resulting in Error 405: Bad Request

SOLVED / SEE MY OWN ANSWER FOR DETAILS Encountering a perplexing error that has left me stuck. I am currently facing an issue where I am trying to send an audio recording captured by the user in my Next.js Frontend to my Next.js API, which appears to be f ...

React - updating key prop does not trigger re-render of child component

I have implemented react-infinite-scroll to display a continuous feed of data. My goal is to refresh the data feed whenever the user makes any changes to their settings. To achieve this, I am utilizing a key prop for the InfiniteScroll component. The conc ...

Error: Papa is not defined. The file was loaded from the CDN in the header section

I have integrated the cdn hosted lib for PapaParse in my HTML header. However, when I execute my JavaScript file and it reaches the function where I call Papa.unparse(data); It throws an error stating that Papa is undefined. This has left me puzzled as I h ...

Tips for Keeping Sub Menu Visible Without Having to Click

I am working on an HTML navigation menu that opens submenus on click like this... $("#nav_evnavmenu > li > a").click(function () { // bind onclick if ($(this).parent().hasClass('selected')) { $("#nav_evnavmenu .selected div div ...

Assign a custom value to the ng-options and ensure that the first option is selected by default

Hey there, I'm currently working on the following: $scope.test = [ {"value" : 0, "text" : "00:00"}, {"value" : 900, "text" : "00:15"}, {"value" : 1800, "text" : "00:30"} ]; and in my select element, this is what I hav ...

Transform Django Model Instance from Serialized Back to Object using Ajax

Currently, I'm utilizing Ajax to search for a model instance. Once found, I return that instance and pass it as a variable to a template tag within my template. To achieve this, in my view, I serialize the object before sending it to the Ajax success ...

Experimenting with NGXS selectors: A comprehensive guide

Hey there, I am currently utilizing the NGXS state management library in my application. I have a selector set up like this and everything seems to be functioning correctly. However, while testing the app, I encountered the following error message: "PrintI ...

Another project cannot import the library that was constructed

I am in the process of creating a library that acts as a wrapper for a soap API. The layout of the library is structured like this: |-node_modules | |-src | |-soapWrapperLibrary.ts | |-soapLibraryClient.ts | |-types | |-soapResponseType.d.ts The libra ...

Buttons aligned vertically alongside an input text field

I am trying to align two buttons vertically under an input text box with the middle aligned. This is what I have done so far: jQuery(document).ready(function($) { // Implementing bootstrap minus and plus plugin // Reference: http://jsfiddle.net/lael ...

Arrange Bootstrap-Vue table in a custom order of days (mon, tue, wed) instead of the default

I'm working on a table that populates data from a database using Bootstrap-vue. The database includes a field labeled "day" which contains string values like "mon", "tue", "wed", and so on. I need the table to sort this column by day order rather than ...

In Vue.js2, you can easily compare two arrays of objects that have the same values and then make changes or add properties from one array to the other

I am working with an array of objects fetched from an API (), which is linked to a variable that serves as the v-model for an input. Whenever the variable changes, so does the array through a function that triggers the API call on @keyup. The structure of ...