atoyebs
07/10/2022, 7:04 PMatoyebs
07/10/2022, 7:04 PMsession in Error.UNAUTHORISED ==> undefined SessionError {
type: 'UNAUTHORISED',
message: 'Session does not exist. Are you sending the session tokens in the request as cookies?',
payload: { clearCookies: true },
errMagic: 'ndskajfasndlfkj435234krjdsa',
fromRecipe: 'session'
}
atoyebs
07/10/2022, 7:04 PMindex.tsx
file looks like:
import React, { ReducerAction } from "react";
import Head from "next/head";
import styles from "../styles/Home.module.scss";
import ThirdPartyEmailPassword from "supertokens-auth-react/recipe/thirdpartyemailpassword";
import dynamic from "next/dynamic";
import * as supertokensNode from "supertokens-node";
import { backendConfig } from "../config/backendConfig";
import Session from "supertokens-node/recipe/session";
import { AuthMode } from "../types/auth";
import { useRouter } from "next/router";
const ThirdPartyEmailPasswordAuthNoSSR = dynamic(
new Promise<React.FC<React.PropsWithChildren>>((res) =>
res(ThirdPartyEmailPassword.ThirdPartyEmailPasswordAuth)
),
{ ssr: false }
);
export async function getServerSideProps(context) {
// this runs on the backend, so we must call init on supertokens-node SDK
let session;
try {
const backendConf = backendConfig();
supertokensNode?.init(backendConf);
session = await Session.getSession(context.req, context.res);
console.log("session in getServerSideProps ==> ", session);
} catch (err) {
if (err.type === Session.Error.TRY_REFRESH_TOKEN) {
console.log("session in Error.TRY_REFRESH_TOKEN ==> ", session, err);
return { props: { fromSupertokens: "needs-refresh" } };
} else if (err.type === Session.Error.UNAUTHORISED) {
console.log("session in Error.UNAUTHORISED ==> ", session, err);
return { props: {} };
} else {
throw err;
}
}
return {
props: { userId: session.getUserId() },
};
}
export default function Home(props) {
return (
<ThirdPartyEmailPasswordAuthNoSSR>
<ProtectedPage userId={props?.userId} />
</ThirdPartyEmailPasswordAuthNoSSR>
);
}
atoyebs
07/10/2022, 7:04 PM_app.tsx
await Session.attemptRefreshingSession();
is returning true, so the page is attempting a reload
But for some reason my page never loads, it used to load before this error, but now I can't get my screen to show.
I welcome any adviceatoyebs
07/10/2022, 8:16 PM