Next auth - custom signIn page redirection problem
Unanswered
Araucanian herring posted this in #help-forum
Araucanian herringOP
Hello, i have a problem in production environment (next.js app v.14.0.4, next auth 4.24.5) in vercel. After successful sign in i have 302 and then 304 redirect (200 redirect is a temporary fix developed with useEffect). In local dev i have just 200 redirect and it's fine. When i pass redirect: true it will redirect to homepage with only 200, but it will also broke couple more things. Thanks for any help!
Here is my signIn code:
next auth options:
Here is my signIn code:
try {
const res = await signIn("credentials", {
email,
password,
redirect: false,
callbackUrl: "/",
});
if (res?.error || !res) {
setError(res.error);
setIsSpinner(false);
toast.error("Wystąpił błąd");
return;
}
setCookie("isFirstLogin", true);
setIsSpinner(false);
} catch (error) {
setIsSpinner(false);
setError(error);
toast.error("Wystąpił błąd");
throw new Error(error);
}next auth options:
callbacks: {
async jwt({ token, user }) {
return { ...token, ...user };
},
async session({ session, user, token }) {
if (token.user) {
session.user = token.user;
session.user.token = token.jti;
}
return session;
},
async signIn({ user, account, profile, email, credentials }) {
return true;
},
async redirect({ url, baseUrl }) {
return baseUrl;
},
},
session: {
strategy: "jwt",
maxAge: 60 * 60 * 12,
},
secret: process.env.NEXTAUTH_SECRET,
pages: {
signIn: "/logowanie",
},