forked from rahulsainlll/git-trace
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
5967f5a
commit f28f808
Showing
6 changed files
with
87 additions
and
83 deletions.
There are no files selected for viewing
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,82 +1,5 @@ | ||
import prisma from "@/lib/prisma"; | ||
import { compare } from "bcrypt"; | ||
import NextAuth, { type NextAuthOptions } from "next-auth"; | ||
import CredentialsProvider from "next-auth/providers/credentials"; | ||
|
||
export const authOptions: NextAuthOptions = { | ||
session: { | ||
strategy: "jwt", | ||
}, | ||
providers: [ | ||
CredentialsProvider({ | ||
name: "Sign in", | ||
credentials: { | ||
email: { | ||
label: "Email", | ||
type: "email", | ||
placeholder: "[email protected]", | ||
}, | ||
password: { label: "Password", type: "password" }, | ||
}, | ||
async authorize(credentials) { | ||
if (!credentials?.email || !credentials.password) { | ||
return null; | ||
} | ||
|
||
try { | ||
const user = await prisma.user.findUnique({ | ||
where: { email: credentials.email }, | ||
}); | ||
|
||
if (!user) { | ||
console.log("User not found"); | ||
return null; | ||
} | ||
|
||
const isPasswordValid = await compare( | ||
credentials.password, | ||
user.password | ||
); | ||
|
||
if (!isPasswordValid) { | ||
console.log("Invalid password"); | ||
return null; | ||
} | ||
|
||
return { | ||
id: user.id.toString(), | ||
email: user.email, | ||
}; | ||
} catch (error) { | ||
console.error("Error in authorization:", error); | ||
return null; | ||
} | ||
}, | ||
}), | ||
], | ||
callbacks: { | ||
session: ({ session, token }) => { | ||
return { | ||
...session, | ||
user: { | ||
...session.user, | ||
id: token.id, | ||
}, | ||
}; | ||
}, | ||
jwt: ({ token, user }) => { | ||
if (user) { | ||
return { | ||
...token, | ||
}; | ||
} | ||
return token; | ||
}, | ||
}, | ||
pages: { | ||
signIn: "/auth/signin", | ||
}, | ||
}; | ||
import { authOptions } from "@/lib/auth"; | ||
import NextAuth from "next-auth/next"; | ||
|
||
const handler = NextAuth(authOptions); | ||
export { handler as GET, handler as POST }; |
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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import prisma from "@/lib/prisma"; | ||
import { compare } from "bcrypt"; | ||
import NextAuth, { type NextAuthOptions } from "next-auth"; | ||
import CredentialsProvider from "next-auth/providers/credentials"; | ||
|
||
export const authOptions: NextAuthOptions = { | ||
session: { | ||
strategy: "jwt", | ||
}, | ||
providers: [ | ||
CredentialsProvider({ | ||
name: "Sign in", | ||
credentials: { | ||
email: { | ||
label: "Email", | ||
type: "email", | ||
placeholder: "[email protected]", | ||
}, | ||
password: { label: "Password", type: "password" }, | ||
}, | ||
async authorize(credentials) { | ||
if (!credentials?.email || !credentials.password) { | ||
return null; | ||
} | ||
|
||
try { | ||
const user = await prisma.user.findUnique({ | ||
where: { email: credentials.email }, | ||
}); | ||
|
||
if (!user) { | ||
console.log("User not found"); | ||
return null; | ||
} | ||
|
||
const isPasswordValid = await compare( | ||
credentials.password, | ||
user.password | ||
); | ||
|
||
if (!isPasswordValid) { | ||
console.log("Invalid password"); | ||
return null; | ||
} | ||
|
||
return { | ||
id: user.id.toString(), | ||
email: user.email, | ||
}; | ||
} catch (error) { | ||
console.error("Error in authorization:", error); | ||
return null; | ||
} | ||
}, | ||
}), | ||
], | ||
callbacks: { | ||
session: ({ session, token }) => { | ||
return { | ||
...session, | ||
user: { | ||
...session.user, | ||
id: token.id, | ||
}, | ||
}; | ||
}, | ||
jwt: ({ token, user }) => { | ||
if (user) { | ||
return { | ||
...token, | ||
id: user.id, | ||
}; | ||
} | ||
return token; | ||
}, | ||
}, | ||
pages: { | ||
signIn: "/auth/signin", | ||
}, | ||
}; | ||
|