In Next.js Pages Router applications, use getKindeServerSession(req, res) to obtain a session handler object. This handler provides methods to retrieve user information, tokens, permissions, and feature flags from the current session.
Important Compatibility Note:
- This method is designed exclusively for the Pages Router.
- It is not compatible with the App Router. App Router users should use the
refreshData method in useKindeBrowserClient instead.
import { getKindeServerSession } from "@kinde-oss/kinde-auth-nextjs";
export async function getServerSideProps({ req, res }) {
const { getKindeServerSession } = await getKindeServerSession(req, res);
const user = await getUser();
const isAuthenticated = await isAuthenticated();
const accessToken = await getAccessToken();
return {
props: {
user,
isAuthenticated,
},
};
}