Recently, I've started using Typscript with a NextJS14 project that utilizes NextAuth for authentication. While there weren't any errors in the JavaScript version of my code, I encountered an error when working with TypeScript.
This is a snippet of my code:
import { AuthOptions } from 'next-auth';
import NextAuth from 'next-auth/next';
import CredentialsProvider from 'next-auth/providers/credentials';
const Backend_URL = 'http://localhost:5031/api/';
export const authOptions: AuthOptions = {
/* Code block shortened for brevity */
};
const handler = NextAuth(authOptions);
export { handler as GET, handler as POST };
The issue arises in the session section where I want to nullify the session if it has expired and redirect the user to the login page.
In my `next-auth.d.ts` file:
/* TypeScript definitions here */
My backend sends me the required validity date for the token, and I intend to delete the token once this date expires.
The Error;
[{
/* TypeScript error details */
}]