I am struggling to show the appropriate response message from the 'authorize' function the when the user tries to sign-in. The message is not being received in my signIn form:
This is part of the signin page that handles submission:
"use client";
import React, { useState } from "react";
import Link from "next/link";
import { cn } from "@/lib/utils";
// Zod and form validation
import { useForm, SubmitHandler } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { authFormSchema } from "./formValidationSchemas/formValidationSchema";
// Compons
import { Input } from "@mui/joy";
import { Button } from "../ui/button";
// Icons
import { Eye, EyeOff, Lock, Mail, User } from "lucide-react";
import { SignUpFormTypes } from "@/types/authTypes/authTypes";
import { signIn } from "next-auth/react";
import { z } from "zod";
And here is my auth.ts with authroize -----------------------------------------------
import NextAuth, { CredentialsSignin, User } from "next-auth";
import Credentials from "next-auth/providers/credentials";
import Github from "next-auth/providers/github";
import Google from "next-auth/providers/google";
import connectDB from "@/utils/connectDB";
import userModel from "@/app/models/userModel";
import bcrypt from "bcryptjs";
I am struggling to show the appropriate response message from the 'authorize' function the when the user tries to sign-in. The message is not being received in my signIn form:
This is part of the signin page that handles submission: "use client"; import React, { useState } from "react"; import Link from "next/link"; import { cn } from "@/lib/utils";
// Zod and form validation import { useForm, SubmitHandler } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; import { authFormSchema } from "./formValidationSchemas/formValidationSchema";
// Compons import { Input } from "@mui/joy"; import { Button } from "../ui/button";
// Icons import { Eye, EyeOff, Lock, Mail, User } from "lucide-react"; import { SignUpFormTypes } from "@/types/authTypes/authTypes"; import { signIn } from "next-auth/react"; import { z } from "zod";
const AuthForm = ({ isLogin }: { isLogin: boolean }) => { // Form validation setups const { register, handleSubmit, setError, formState: { errors }, } = useForm({ resolver: zodResolver(authFormSchema) });
// States const [passwordType, setPasswordType] = useState("password");
const togglePassType = () => { passwordType === "password" ? setPasswordType("text") : setPasswordType("password"); };
// On submit handler function const onSubmit: SubmitHandler = async (
data: z.infer
) => {
if (isLogin) {
// Handle sign in
const res = await signIn("credentials", {
email: data.email,
password: data.password,
redirect: false, //Prevent redirect
});
};
return ( <form onSubmit={handleSubmit(onSubmit)} className={cn(isLogin ? "grid" : "grid grid-cols-2 gap-x-2 text-inherit")}
); };
export default AuthForm;
And here is my auth.ts with authroize -----------------------------------------------
import NextAuth, { CredentialsSignin, User } from "next-auth"; import Credentials from "next-auth/providers/credentials"; import Github from "next-auth/providers/github"; import Google from "next-auth/providers/google"; import connectDB from "@/utils/connectDB"; import userModel from "@/app/models/userModel"; import bcrypt from "bcryptjs";
export const { handlers, signIn, signOut, auth } = NextAuth({ providers: [ Google, Credentials({ name: "Credentials", credentials: { email: { label: "Email", type: "email" }, password: { label: "Password", type: "password" }, },
],
pages: { signIn: "/login", },
callbacks: { async session({ session, token }) { if (token && token?.role) { session.user.id = token.id as string; session.user.role = token.role as string; } return session; },
}, });