fixed credentials provider
This commit is contained in:
parent
96647fbf5a
commit
d089fe461a
2 changed files with 34 additions and 31 deletions
|
@ -9,35 +9,38 @@ import clientPromise from "../../../../libs/mongoConnect"
|
|||
import { UserInfo } from "../../models/UserInfo"
|
||||
|
||||
export const authOptions = {
|
||||
secret: process.env.SECRET,
|
||||
adapter: MongoDBAdapter(clientPromise),
|
||||
providers: [
|
||||
GoogleProvider({
|
||||
clientId: process.env.GOOGLE_CLIENT_ID,
|
||||
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
|
||||
}),
|
||||
CredentialsProvider({
|
||||
name: 'Credentials',
|
||||
id: 'credentials',
|
||||
credentials: {
|
||||
username: { label: "Email", type: "email", placeholder: "test@example.com" },
|
||||
password: { label: "Password", type: "password" }
|
||||
},
|
||||
async authorize(credentials, req) {
|
||||
const email = credentials?.email;
|
||||
const password = credentials?.password;
|
||||
secret: process.env.SECRET,
|
||||
adapter: MongoDBAdapter(clientPromise),
|
||||
providers: [
|
||||
GoogleProvider({
|
||||
clientId: process.env.GOOGLE_CLIENT_ID,
|
||||
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
|
||||
}),
|
||||
CredentialsProvider({
|
||||
name: 'Credentials',
|
||||
id: 'credentials',
|
||||
credentials: {
|
||||
username: { label: "Email", type: "email", placeholder: "test@example.com" },
|
||||
password: { label: "Password", type: "password" },
|
||||
},
|
||||
async authorize(credentials, req) {
|
||||
const email = credentials?.email;
|
||||
const password = credentials?.password;
|
||||
|
||||
mongoose.connect(process.env.MONGO_URL);
|
||||
mongoose.connect(process.env.MONGO_URL);
|
||||
|
||||
const user = await User.findOne({email});
|
||||
const passwordOk = user && bcrypt.compareSync(password, user.password);
|
||||
if(passwordOk){
|
||||
return user
|
||||
}
|
||||
return null
|
||||
}
|
||||
}),
|
||||
],
|
||||
const user = await User.findOne({email});
|
||||
const passwordOk = user && bcrypt.compareSync(password, user.password);
|
||||
if(passwordOk){
|
||||
return user;
|
||||
} else {
|
||||
return null;
|
||||
}}
|
||||
}),
|
||||
],
|
||||
session:{
|
||||
strategy: "jwt"
|
||||
},
|
||||
};
|
||||
|
||||
export async function isAdmin(){
|
||||
|
|
|
@ -8,15 +8,15 @@ import { signIn } from "next-auth/react";
|
|||
const LoginPage = () => {
|
||||
const [email, setEmail] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [loginInProgress, setLoginInProgreass] = useState(false);
|
||||
const [loginInProgress, setLoginInProgress] = useState(false);
|
||||
|
||||
async function handleFormSubmit(ev) {
|
||||
ev.preventDefault();
|
||||
setLoginInProgreass(true)
|
||||
setLoginInProgress(true)
|
||||
|
||||
await signIn('credentials', {email, password, callbackUrl:'/'})
|
||||
await signIn('credentials', {email, password, callbackUrl:'/', redirect: true});
|
||||
|
||||
setLoginInProgreass(false)
|
||||
setLoginInProgress(false)
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue