Hi I'm using SuperTokens with NextJS. I am trying to protect a SSR page, so I implemented this code ...
k
Hi I'm using SuperTokens with NextJS. I am trying to protect a SSR page, so I implemented this code
Copy code
const { session, hasToken, hasInvalidClaims } = await getSSRSession();

    if (!session) {
        if (!hasToken) {
            return redirect("/auth");
        }

        if (hasInvalidClaims) {
            return <SessionAuthForNextJS />;
        } else {
            return <TryRefreshComponent />;
        }
    }
But it redirect to /auth and therefore after I am back to the / page instead of the page from with I called redirect. How can I do so that it redirect to the previous page ? Thanks.
r
hey @kyomster when redirecting to
/auth
, you can do
/auth?redirectToPath=<PAGE PATH TO REDIRECT BACK TO>
. Note that you have to url encode the value you set to
redirectToPath
k
How can I get the page url to redirect to ? I did not find a way to find to get the current page url so that I can redirect back to it.
r
I guess it’s the current request path? Since it’s server side rendering
k
yes, and how can i get it from a SSR page ?
r
I’m not sure. But you can ask the NextJS community.
4 Views