NEXT JS Login issue in production
Unanswered
Argente Brun posted this in #help-forum
Argente BrunOP
as per documentation
i have provided nextauth_secret in .env file
but it show error while logging into the system
"
there is a problem with the server configuration. check the server logs for more information.
"
i have provided nextauth_secret in .env file
but it show error while logging into the system
"
there is a problem with the server configuration. check the server logs for more information.
"
7 Replies
Philippine Crocodile
Can you show screenshots + code?
Also, what's the error in the logs?
Argente BrunOP
This is my [...nextauth].ts file
"
import { isAxiosError } from "axios";
import NextAuth, { NextAuthOptions } from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";
import { httpClient } from "../../../services/service-axios";
type User = {
token: string;
message: string | null;
isAuthenticated: boolean;
expirationDuration: number;
refreshToken: string;
userType: number;
role: 0 | 1;
userId: string;
fullName: string;
email?: string;
mobileNumber?: string;
imageUrl?: string;
};
const loginUrl = "/api/useraccount/login";
const authOptions: NextAuthOptions = {
session: {
strategy: "jwt",
},
providers: [
CredentialsProvider({
type: "credentials",
credentials: {},
async authorize(credentials, req) {
const { email, password } = credentials as {
email: string;
password: string;
};
try {
const req = await httpClient.post<User>(loginUrl, {
emailOrMobile: email,
password,
});
const user = req.data;
return { id: user.userId, ...user };
} catch (err) {
if (isAxiosError(err)) {
throw new Error(JSON.stringify(err.response?.data));
}
throw err;
}
},
}),
],
pages: {
signIn: "/auth/signin",
// error: '/auth/error',
// signOut: '/auth/signout'
},
callbacks: {
jwt({ account, token, user, profile, session }) {
token.test = user;
if (user) {
// @ts-ignore
token.token = user.token;
}
return token;
},
session: ({ session, token, user }) => {
session.user = token;
return session;
},
},
secret: process.env.NEXTAUTH_SECRET,
};
export default NextAuth(authOptions);
"
"
import { isAxiosError } from "axios";
import NextAuth, { NextAuthOptions } from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";
import { httpClient } from "../../../services/service-axios";
type User = {
token: string;
message: string | null;
isAuthenticated: boolean;
expirationDuration: number;
refreshToken: string;
userType: number;
role: 0 | 1;
userId: string;
fullName: string;
email?: string;
mobileNumber?: string;
imageUrl?: string;
};
const loginUrl = "/api/useraccount/login";
const authOptions: NextAuthOptions = {
session: {
strategy: "jwt",
},
providers: [
CredentialsProvider({
type: "credentials",
credentials: {},
async authorize(credentials, req) {
const { email, password } = credentials as {
email: string;
password: string;
};
try {
const req = await httpClient.post<User>(loginUrl, {
emailOrMobile: email,
password,
});
const user = req.data;
return { id: user.userId, ...user };
} catch (err) {
if (isAxiosError(err)) {
throw new Error(JSON.stringify(err.response?.data));
}
throw err;
}
},
}),
],
pages: {
signIn: "/auth/signin",
// error: '/auth/error',
// signOut: '/auth/signout'
},
callbacks: {
jwt({ account, token, user, profile, session }) {
token.test = user;
if (user) {
// @ts-ignore
token.token = user.token;
}
return token;
},
session: ({ session, token, user }) => {
session.user = token;
return session;
},
},
secret: process.env.NEXTAUTH_SECRET,
};
export default NextAuth(authOptions);
"
@Philippine Crocodile @Siberian please provide me the solution
everything is working fine in development environment
But while I login in production environment it always throws this error.
everything is working fine in development environment
But while I login in production environment it always throws this error.
Argente BrunOP
@Philippine Crocodile @Siberian