So, i have been trying to figure this out all day. I'm freshly new to NextJS and im surprised i even got this far and always got confused on the session signup.
using Username,Password to login. That's working but can't get it to save to the session.
ideas?
import type { NextAuthOptions } from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";
import bcrypt from "bcrypt";
import User from '../../../../models/user'
export const options: NextAuthOptions = {
providers: [
CredentialsProvider({
name: "Credentials",
credentials: {
username: { label: 'Username', type: 'text', placeholder: 'Username' },
password: { label: 'Password', type: 'password', placeholder: 'Password' }
},
async authorize(credentials, req) {
const userCheck = await User.findOne({ where: { username: credentials?.username } })
if (userCheck) {
bcrypt.compare(credentials?.password, userCheck.hashPassword, function (err, result) {
if (result === true) {
console.log(JSON.stringify(userCheck))
return JSON.stringify(userCheck);
} else throw Error('Sorry, password doesn\'t match')
})
} else throw Error('Sorry, login failed')
}
})
],
session: {
strategy: 'jwt'
},
callbacks: {
async signIn({ user, account, profile, email, credentials }) {
return true
}
}
}
