Next.js Discord

Discord Forum

Next-Auth "signIn()" function not working as expected

Answered
Exzotic posted this in #help-forum
Open in Discord
Hello! I am trying to login from a custom signin page, am using this code on the login page:
(the return value is undefined)
    const handleSubmit = async () => {
        await signIn("credentials", { redirect: true, callbackUrl: "/" }, { username: emailRef.current!.value, password: passwordRef.current!.value });
    };
Answered by Exzotic
Oh I was using "username" instead of email, my bad 🤣
View full answer

20 Replies

export const authOptions: AuthOptions = {
    pages: {
        signIn: "/login",
        newUser: "/"
    },
    providers: [
        CredentialsProvider({
            name: "Credentials",
            credentials: {
                email: { type: 'email', placeholder: 'email@email.com' },
                password: { type: 'password', placeholder: '*****' },
            },
            // @ts-ignore
            async authorize(credentials, req) {
                if (!credentials?.email || !credentials?.password) {
                    return null
                }

                const user = await prisma.user.findUnique({
                    where: {
                        email: credentials.email
                    }
                })

                if (!user) return;

                if(!await compare(credentials.password, user.password!)) return;

                return user;
            },
        })
    ],
    session: {
        strategy: "jwt"
    }
}

Heres my config ^
signin should take you to a different page
idk if I've ever seen credentials passed like that
@Marchy signin should take you to a different page
The signin page is on /login
and the way I passed credentials is just how the ts types say
ah right
await signIn("credentials", { username: emailRef.current!.value, password: passwordRef.current!.value, redirect: true, callbackUrl: "/" })
changing it to this doesnt help much either
<button onClick={() => signIn("credentials")}>Sign in</button>
do I not need to pass data
nope, it redirects to the login page that next-auth generates
if it's configured
But I want to use this custom page on /login instead of the default one
Ive looked up stuff on youtube and in the docs but im not doing anything different
Oh I was using "username" instead of email, my bad 🤣
Answer