Added register
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import NextAuth, { AuthOptions } from 'next-auth';
|
||||
import { AuthOptions } from 'next-auth';
|
||||
import { PrismaAdapter } from '@next-auth/prisma-adapter';
|
||||
import Credentials from 'next-auth/providers/credentials';
|
||||
import { prisma } from '@repo/db';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import bcrypt from 'bcryptjs';
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
export const options = {
|
||||
export const options: AuthOptions = {
|
||||
providers: [
|
||||
Credentials({
|
||||
credentials: {
|
||||
@@ -18,6 +19,7 @@ export const options = {
|
||||
where: { email: credentials.email },
|
||||
});
|
||||
if (bcrypt.compareSync(credentials.password, user.password)) {
|
||||
console.log('User found and password correct', user);
|
||||
return user;
|
||||
}
|
||||
return null;
|
||||
@@ -32,6 +34,7 @@ export const options = {
|
||||
strategy: 'jwt',
|
||||
maxAge: 30 * 24 * 60 * 60,
|
||||
},
|
||||
|
||||
adapter: PrismaAdapter(prisma),
|
||||
events: {
|
||||
async signIn(message) {
|
||||
@@ -44,6 +47,24 @@ export const options = {
|
||||
console.log('User created!', { message });
|
||||
},
|
||||
},
|
||||
callbacks: {
|
||||
jwt: async ({ token, user }) => {
|
||||
if (user) {
|
||||
token.uid = user;
|
||||
}
|
||||
|
||||
return token;
|
||||
},
|
||||
session: async ({ session, token }: any) => {
|
||||
// here we put session.useData and put inside it whatever you want to be in the session
|
||||
// here try to console.log(token) and see what it will have
|
||||
// sometimes the user get stored in token.uid.userData
|
||||
// sometimes the user data get stored in just token.uid
|
||||
session.userData = token.uid.userData;
|
||||
|
||||
return session;
|
||||
},
|
||||
},
|
||||
pages: {
|
||||
signIn: '/login',
|
||||
signOut: '/logout',
|
||||
|
||||
Reference in New Issue
Block a user