试图在会议上增加习俗数据。 用户,但其工作。 奇怪的是,如果我发出:
const user = { id: 1 , name: "J Smith", email: "[email protected]", };
然后,我收到了我的网页上的信息。 jsx使用Session,并在 con中印刷:
const { data: session } = useSession(); console.log("in form session: ", session);
但问题是,在我试图向用户增加习俗信息时:
const user = { userId: res.data.data.login.userId, companyId: res.data.data.login.companyId, };
只有在我使用假冒、姓名和电子邮件时,它才能在没有习惯信息的情况下用空出用户物体。
这是我的全面法典:
import NextAuth from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";
import axios from "axios";
const handler = NextAuth({
providers: [
CredentialsProvider({
name: "Credentials",
credentials: {
email: {
label: "Email",
type: "email",
placeholder: "Enter your email",
},
password: { label: "Password", type: "password" },
},
async authorize(credentials, req) {
const res = await axios({
method: "POST",
url: `${process.env.NEXT_PUBLIC_AUTH_URL}/api`,
data: {
query: `
query Login($email: String!, $password: String!) {
login(email: $email, password: $password) {
userId
token
tokenExpiration
companyId
}
}
`,
variables: {
email: credentials.email,
password: credentials.password,
},
},
});
// Validation
if (res.data.errors) {
throw new Error(res.data.errors[0].message);
}
const user = {
userId: res.data.data.login.userId,
companyId: res.data.data.login.companyId,
};
if (user) {
return user;
}
// // Return null if user data could not be retrieved
return null;
},
}),
],
session: {
strategy: "jwt",
},
pages: {
signIn: "/login",
signOut: "/logout",
},
secret: process.env.NEXTAUTH_SECRET,
});
export { handler as GET, handler as POST };
Someone knows how to fix this? Thanks