-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
359 additions
and
940 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,5 @@ | ||
/* eslint-disable arrow-body-style */ | ||
import { compare } from 'bcrypt'; | ||
import NextAuth, { type NextAuthOptions } from 'next-auth'; | ||
import CredentialsProvider from 'next-auth/providers/credentials'; | ||
import { prisma } from '@/lib/prisma'; | ||
|
||
export const authOptions: NextAuthOptions = { | ||
session: { | ||
strategy: 'jwt', | ||
}, | ||
providers: [ | ||
CredentialsProvider({ | ||
name: 'Email and Password', | ||
credentials: { | ||
email: { | ||
label: 'Email', | ||
type: 'email', | ||
placeholder: '[email protected]', | ||
}, | ||
password: { label: 'Password', type: 'password' }, | ||
}, | ||
async authorize(credentials) { | ||
if (!credentials?.email || !credentials.password) { | ||
return null; | ||
} | ||
const user = await prisma.user.findUnique({ | ||
where: { | ||
email: credentials.email, | ||
}, | ||
}); | ||
if (!user) { | ||
return null; | ||
} | ||
|
||
const isPasswordValid = await compare(credentials.password, user.password); | ||
if (!isPasswordValid) { | ||
return null; | ||
} | ||
|
||
return { | ||
id: `${user.id}`, | ||
email: user.email, | ||
randomKey: user.role, | ||
}; | ||
}, | ||
}), | ||
], | ||
pages: { | ||
signIn: '/auth/signin', | ||
signOut: '/auth/signout', | ||
// error: '/auth/error', | ||
// verifyRequest: '/auth/verify-request', | ||
// newUser: '/auth/new-user' | ||
}, | ||
callbacks: { | ||
session: ({ session, token }) => { | ||
// console.log('Session Callback', { session, token }) | ||
return { | ||
...session, | ||
user: { | ||
...session.user, | ||
id: token.id, | ||
randomKey: token.randomKey, | ||
}, | ||
}; | ||
}, | ||
jwt: ({ token, user }) => { | ||
// console.log('JWT Callback', { token, user }) | ||
if (user) { | ||
const u = user as unknown as any; | ||
return { | ||
...token, | ||
id: u.id, | ||
randomKey: u.randomKey, | ||
}; | ||
} | ||
return token; | ||
}, | ||
}, | ||
}; | ||
import NextAuth from 'next-auth'; | ||
import authOptions from '@/lib/authOptions'; | ||
|
||
const handler = NextAuth(authOptions); | ||
export { handler as GET, handler as POST }; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* eslint-disable arrow-body-style */ | ||
import { compare } from 'bcrypt'; | ||
import { type NextAuthOptions } from 'next-auth'; | ||
import CredentialsProvider from 'next-auth/providers/credentials'; | ||
import { prisma } from '@/lib/prisma'; | ||
|
||
const authOptions: NextAuthOptions = { | ||
session: { | ||
strategy: 'jwt', | ||
}, | ||
providers: [ | ||
CredentialsProvider({ | ||
name: 'Email and Password', | ||
credentials: { | ||
email: { | ||
label: 'Email', | ||
type: 'email', | ||
placeholder: '[email protected]', | ||
}, | ||
password: { label: 'Password', type: 'password' }, | ||
}, | ||
async authorize(credentials) { | ||
if (!credentials?.email || !credentials.password) { | ||
return null; | ||
} | ||
const user = await prisma.user.findUnique({ | ||
where: { | ||
email: credentials.email, | ||
}, | ||
}); | ||
if (!user) { | ||
return null; | ||
} | ||
|
||
const isPasswordValid = await compare(credentials.password, user.password); | ||
if (!isPasswordValid) { | ||
return null; | ||
} | ||
|
||
return { | ||
id: `${user.id}`, | ||
email: user.email, | ||
randomKey: user.role, | ||
}; | ||
}, | ||
}), | ||
], | ||
pages: { | ||
signIn: '/auth/signin', | ||
signOut: '/auth/signout', | ||
// error: '/auth/error', | ||
// verifyRequest: '/auth/verify-request', | ||
// newUser: '/auth/new-user' | ||
}, | ||
callbacks: { | ||
session: ({ session, token }) => { | ||
// console.log('Session Callback', { session, token }) | ||
return { | ||
...session, | ||
user: { | ||
...session.user, | ||
id: token.id, | ||
randomKey: token.randomKey, | ||
}, | ||
}; | ||
}, | ||
jwt: ({ token, user }) => { | ||
// console.log('JWT Callback', { token, user }) | ||
if (user) { | ||
const u = user as unknown as any; | ||
return { | ||
...token, | ||
id: u.id, | ||
randomKey: u.randomKey, | ||
}; | ||
} | ||
return token; | ||
}, | ||
}, | ||
secret: process.env.NEXTAUTH_SECRET, | ||
}; | ||
|
||
export default authOptions; |