System Information
- Strapi Version: v4
- Operating System:
- Database:
- Node Version: 16.16.0
- NPM Version: 8.15.0
I have a problem with Next Auth, it gives me an error:
POST http://localhost:1338/api/callback/credentials 405 (Method Not Allowed)
pages/api/auth/[…nextauth].js
import NextAuth from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";
export default NextAuth({
theme: {
colorScheme: 'light',
},
debug: true,
session: {
strategy: 'jwt',
},
jwt: {
secret: 'secret',
},
providers: [
CredentialsProvider({
//id: 'email-login',
name: 'Credentials',
credentials: {
identifier: { label: "email", type: "text", placeholder: "email" },
password: { label: "password", type: "password", placeholder: "password" },
},
async authorize({ credentials, req }) {
const res = await fetch(`${process.env.apiPublicUrl}/auth/local`, {
method: 'POST',
body: JSON.stringify(credentials),
headers: {
'Content-Type': 'application/json',
}
})
const user = await res.json()
if (res.ok && user) {
return user
}
return null
}
}),
],
secret: process.env.NEXTAUTH_SECRET,
callbacks: {
async session({ session, user }) {
session.jwt = user.jwt;
session.id = user.id;
return session;
},
async jwt ({ token, user, account }) {
if (user) {
const response = await fetch(`${process.env.apiPublicUrl}/auth/${account.provider}/callback?access_token=${account?.accessToken}`);
const data = await response.json();
token.jwt = data.jwt;
token.id = data.user.id;
}
return token;
},
},
pages: {
//signIn: '/login',
}
})