mirror of
https://github.com/jorgev259/soc_site-astro.git
synced 2025-06-29 07:57:41 +00:00
Add Prisma ORM
This commit is contained in:
parent
e8530f0f01
commit
bce35d73ca
15 changed files with 1296 additions and 148 deletions
|
|
@ -1,40 +1,31 @@
|
|||
import { CredentialsSignin } from '@auth/core/errors'
|
||||
import { defineConfig } from 'auth-astro'
|
||||
import Credentials from "@auth/core/providers/credentials"
|
||||
import Credentials from '@auth/core/providers/credentials'
|
||||
import bcrypt from 'bcrypt'
|
||||
|
||||
import User from 'sequelize/models/user'
|
||||
|
||||
declare module "@auth/core" {
|
||||
interface Session {
|
||||
id: string
|
||||
username: string
|
||||
}
|
||||
}
|
||||
import prismaClient from 'prisma/client'
|
||||
|
||||
class InvalidLoginError extends CredentialsSignin {
|
||||
code = "Invalid username/email or password"
|
||||
code = 'Invalid username/email or password'
|
||||
}
|
||||
|
||||
export default defineConfig({
|
||||
providers: [
|
||||
Credentials({
|
||||
credentials: {
|
||||
username: { label: "Username" },
|
||||
password: { label: "Password", type: "password" },
|
||||
username: { label: 'Username', required: true },
|
||||
password: { label: 'Password', type: 'password', required: true }
|
||||
},
|
||||
async authorize(credentials) {
|
||||
if (!credentials?.username || !credentials.password) throw new InvalidLoginError()
|
||||
|
||||
const user = await User.findByPk(credentials.username)
|
||||
const user = await prismaClient.users.findUnique({ where: { username: credentials.username } })
|
||||
if (!user) throw new InvalidLoginError()
|
||||
|
||||
// @ts-ignore
|
||||
const valid = await bcrypt.compare(credentials.password, user.password)
|
||||
if (!valid) throw new InvalidLoginError()
|
||||
|
||||
return { id: user.username, username: user.username }
|
||||
},
|
||||
}),
|
||||
],
|
||||
})
|
||||
return { id: user.username }
|
||||
}
|
||||
})
|
||||
]
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue