Help: callback signIn function on multiple Credentials Error {}
Unanswered
dilraba posted this in #help-forum
dilrabaOP
I'm using NextAuth.js with a custom
What could be causing this issue? How I can fix it?
CredentialsProvider. The authorizeand jwt callbacks work fine, but the session cookie isn't set, and the session callback doesn't trigger. The signIn return {} Here's my configuration:import NextAuth from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";
export default NextAuth({
providers: [
CredentialsProvider({
id: "jid",
name: "jid",
credentials: {
someCredentials: {}
},
authorize: async (credentials) => {
if (!!credentials) {
return {
...credentials
};
}
return null;
},
}),
],
callbacks: {
async jwt({ token, user }) {
if (user) {
token = user
}
return token;
},
async session({ session, token }) {
session = token;
return session;
},
},
secret: //secret,
});What could be causing this issue? How I can fix it?
3 Replies
@dilraba I'm using NextAuth.js with a custom ``CredentialsProvider``. The ``authorize``and ``jwt`` callbacks work fine, but the ``session cookie`` isn't set, and the session callback doesn't trigger. The signIn return ``{}`` Here's my configuration:
import NextAuth from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";
export default NextAuth({
providers: [
CredentialsProvider({
id: "jid",
name: "jid",
credentials: {
someCredentials: {}
},
authorize: async (credentials) => {
if (!!credentials) {
return {
...credentials
};
}
return null;
},
}),
],
callbacks: {
async jwt({ token, user }) {
if (user) {
token = user
}
return token;
},
async session({ session, token }) {
session = token;
return session;
},
},
secret: //secret,
});
What could be causing this issue? How I can fix it?
can you try to:
1. set inputs to your
2. Set inside your token some key (
3. Do the same what you did in "2." now for your session callback:
If you did all this and the issue is still not resolved, console.log all the variables inside the specific callbacks and share the results
1. set inputs to your
credentials. For example like this:credentials: {
email: { label: "E-Mail", type: "email", placeholder: "example@gmail.com" },
password: { label: "Password", type: "password" }
}2. Set inside your token some key (
user is mostly null iirc. That could cause the issue). So like like: async jwt({ token, user }) {
if (user) {
token = user
}
- return token;
+ return {
+ ...token,
+ id: "test"
+};
},3. Do the same what you did in "2." now for your session callback:
async session({ session, token }) {
session = token;
- return session;
+ return {
+ ...session,
+ ...token,
+ id: "test"
+};
},If you did all this and the issue is still not resolved, console.log all the variables inside the specific callbacks and share the results
@dilraba solved?
@B33fb0n3 <@729529261295140865> solved?
dilrabaOP
Yes, it's already solved. Turns out the issue caused by authorize function is triggered when the pages load. I changed the strategy. I appreciate your help