next auth not redirecting correctly
Unanswered
maitexu posted this in #help-forum
maitexuOP
Hi! I've tried to set up next auth v4 in my nextjs 14 project.
I use the credentials provider, and this is the [...nextauth] route:
SELECT * FROM users WHERE email=${credentials?.email}
im trying to make a middleware that blocks the user from accessing all the pages that start from /dashboard and redirects it to the login page, but im not bein able to, and i dont know what im doing wrong.
I use the credentials provider, and this is the [...nextauth] route:
import NextAuth from 'next-auth';
import CredentialsProvider from 'next-auth/providers/credentials';
import { compare } from 'bcryptjs';
import { sql } from '@vercel/postgres';
const handler = NextAuth({
secret: process.env.AUTH_SECRET,
session: {
strategy: 'jwt',
},
pages: {
signIn: '/login',
},
providers: [
CredentialsProvider({
credentials: {
email: {},
password: {},
},
async authorize(credentials, req) {
//
const response = await sqlSELECT * FROM users WHERE email=${credentials?.email}
;
const user = response.rows[0];
const passwordCorrect = await compare(
credentials?.password || '',
user.password
);
console.log({ passwordCorrect });
if (passwordCorrect) {
return {
id: user.id,
email: user.email,
};
}
return null;
},
}),
],
});
export { handler as GET, handler as POST };im trying to make a middleware that blocks the user from accessing all the pages that start from /dashboard and redirects it to the login page, but im not bein able to, and i dont know what im doing wrong.