Files
next-learn/dashboard/15-final/auth.ts
Delba de Oliveira a4d66e6527 Add basic metadata and update OG image (#212)
* Bump nextauth

* Move data fetching function to data.ts

- We don't ask the user to add this in the chapter

* Fix imports

* Misc

* Addd metadata

* Add new OG image
2023-10-19 09:37:54 -05:00

39 lines
1004 B
TypeScript

import { NextAuthOptions } from 'next-auth';
import CredentialsProvider from 'next-auth/providers/credentials';
import { getUser } from '@/app/lib/data';
import bcrypt from 'bcrypt';
export const authOptions: NextAuthOptions = {
providers: [
CredentialsProvider({
name: 'Sign-In with Credentials',
credentials: {
password: { label: 'Password', type: 'password' },
email: { label: 'Email', type: 'email' },
},
// @ts-ignore
async authorize(credentials) {
const { email, password } = credentials ?? {};
const user = await getUser(email as string);
if (!user || !password) {
console.log('Missing credentials');
return null;
}
const passwordsMatch = await bcrypt.compare(password, user.password);
if (!passwordsMatch) {
console.log('Invalid credentials');
return null;
}
return user;
},
}),
],
pages: {
signIn: '/login',
},
};