https://supertokens.com/ logo
#support-questions
Title
# support-questions
a

Atoyebs

07/10/2022, 7:04 PM
TRY_REFRESH_TOKEN error
Hi @rp, I'm getting this error:
Copy code
session 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'
}
This is what my
index.tsx
file looks like:
Copy code
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>
  );
}
I understand that the error is saying that the token has expired, and I can see that this line of code in my
_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 advice
Please Ignore
2 Views