Код: Выделить всё
[auth][error] CallbackRouteError: Read more at https://errors.authjs.dev#callbackrouteerror
[auth][cause]: TypeError: fetch failed
Код: Выделить всё
import NextAuth from "next-auth";
import Credentials from "next-auth/providers/credentials";
const URL = process.env.NEXT_PUBLIC_API_URL;
const Token = process.env.NEXT_PUBLIC_TOKEN;
export const { handlers, signIn, signOut, auth } = NextAuth({
providers: [
Credentials({
credentials: {
email: { label: "Email", type: "email" },
password: { label: "Password", type: "password" },
},
authorize: async (credentials) => {
const { email, password } = credentials;
console.log(email, password);
console.log(`${URL}auth/jwt/create/`);
const body = JSON.stringify({ email, password });
const res = await fetch(`${URL}auth/jwt/create/`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body,
});
if (!res.ok) {
throw new Error("Failed to sign in");
} else {
const data = await res.json();
return data;
}
},
}),
],
});
< /code>
My Login Component: < /p>
import { signIn } from "@/app/lib/auth";
import { executeAction } from "../lib/executeAction";
function Page() {
return (
{
"use server";
await executeAction({
actionFn: async () => {
await signIn("credentials", formData);
},
});
}}
>
Sign in
Sign in
);
}
export default Page;
Код: Выделить всё
import { handlers } from "@/app/lib/auth";
export const { GET, POST } = handlers;
next_public_api_url и next_public_token правильно установлены в моем
.env.local файл. /> Бэкэнд работает и достижимый через Postman /Curl. < /li>
< /ul>
Несмотря на это, Fetch выходит из строя внутри авторизации. Что может вызвать это, и как я могу это исправить?
Подробнее здесь: https://stackoverflow.com/questions/795 ... s-provider