I am trying to make Credentials based authentication to my project. However, when I sign in from the default sign in page the request is of type "application/x-www-form-urlencoded" even though in my [...nextauth].ts file specify the header to be of type "application/json". What am I doing wrong or how can I change the request header to be of type "application/json" correctly?
Here is my [...nextauth].ts file:
import { NextAuthOptions } from "next-auth";import NextAuth from "next-auth/next";import CredentialsProvider from "next-auth/providers/credentials";export const authOptions: NextAuthOptions = { providers: [ CredentialsProvider({ name: "Credentials", credentials: { email: { label: "Email", type: "email", placeholder: "example@company.com" }, password: { label: "Password", type: "password" } }, async authorize(credentials) { const res = await fetch("http://localhost:3000/api/user/login", { method: "POST", headers: {"Content-Type": "application/json", }, body: JSON.stringify({ email: credentials?.email, password: credentials?.password, }), }) const user = await res.json() if (user) { return user } else { return null } } }) ], session: { strategy: "jwt", }}export default NextAuth(authOptions)
I've tried to identify the problem from the tutorial I was watching and searching online for similar problems but couldn't find anyone having similar problem. Seems like the aforementioned code should work but for some reason for me the content-type header is still wrong.