fixed credentials provider

This commit is contained in:
Juthatip McDevitt 2024-05-30 00:42:59 -05:00
parent 96647fbf5a
commit d089fe461a
2 changed files with 34 additions and 31 deletions

View file

@ -21,7 +21,7 @@ export const authOptions = {
id: 'credentials', id: 'credentials',
credentials: { credentials: {
username: { label: "Email", type: "email", placeholder: "test@example.com" }, username: { label: "Email", type: "email", placeholder: "test@example.com" },
password: { label: "Password", type: "password" } password: { label: "Password", type: "password" },
}, },
async authorize(credentials, req) { async authorize(credentials, req) {
const email = credentials?.email; const email = credentials?.email;
@ -32,12 +32,15 @@ export const authOptions = {
const user = await User.findOne({email}); const user = await User.findOne({email});
const passwordOk = user && bcrypt.compareSync(password, user.password); const passwordOk = user && bcrypt.compareSync(password, user.password);
if(passwordOk){ if(passwordOk){
return user return user;
} } else {
return null return null;
} }}
}), }),
], ],
session:{
strategy: "jwt"
},
}; };
export async function isAdmin(){ export async function isAdmin(){

View file

@ -8,15 +8,15 @@ import { signIn } from "next-auth/react";
const LoginPage = () => { const LoginPage = () => {
const [email, setEmail] = useState(''); const [email, setEmail] = useState('');
const [password, setPassword] = useState(''); const [password, setPassword] = useState('');
const [loginInProgress, setLoginInProgreass] = useState(false); const [loginInProgress, setLoginInProgress] = useState(false);
async function handleFormSubmit(ev) { async function handleFormSubmit(ev) {
ev.preventDefault(); ev.preventDefault();
setLoginInProgreass(true) setLoginInProgress(true)
await signIn('credentials', {email, password, callbackUrl:'/'}) await signIn('credentials', {email, password, callbackUrl:'/', redirect: true});
setLoginInProgreass(false) setLoginInProgress(false)
} }