Recently, I delved into working with Next.js 14 and Next Auth 5 beta. However, every time I attempt to log in, I encounter the following error: [auth][error][JWTSessionError] [auth][cause]: TypeError: Cannot read properties of undefined (reading 'username'). Initially, I followed a tutorial that did not utilize TypeScript, which worked fine, but as a developer, I need to incorporate TS.
Below is my auth.ts:
import "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";
import { connectDb } from "./lib/utils";
import { User } from "./lib/models";
import bcrypt from "bcrypt";
import { UserType } from "./lib/types";
import NextAuth, { NextAuthConfig } from "next-auth";
// Other module declarations...
// Login function and authConfig setup...
export const { signIn, signOut, auth } = NextAuth(authConfig);
The specific screenshot displaying the error can be viewed here: https://i.sstatic.net/ipvBm.jpg
Upon checking, it appears that the user retrieval process and token manipulation were successful based on console logs. Unsure of the next steps to resolve this issue, any assistance would be greatly appreciated.
Work-in-progress repo: https://github.com/CzechCoder/dashboard_next/tree/main