nezha_dash/auth.ts
仓鼠 37adab9208
Potential fix for code scanning alert no. 7: Use of password hash with insufficient computational effort
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
2025-03-25 15:31:27 +08:00

35 lines
1023 B
TypeScript

import getEnv from "@/lib/env-entry"
import bcrypt from "bcrypt"
import NextAuth from "next-auth"
import CredentialsProvider from "next-auth/providers/credentials"
export const { handlers, signIn, signOut, auth } = NextAuth({
secret:
process.env.AUTH_SECRET ??
bcrypt.hashSync(`this_is_nezha_dash_web_secret_${getEnv("SitePassword")}`, 10),
trustHost: (process.env.AUTH_TRUST_HOST as boolean | undefined) ?? true,
providers: [
CredentialsProvider({
type: "credentials",
credentials: { password: { label: "Password", type: "password" } },
// authorization function
async authorize(credentials) {
const { password } = credentials
if (password === getEnv("SitePassword")) {
return { id: "nezha-dash-auth" }
}
return { error: "Invalid password" }
},
}),
],
callbacks: {
async signIn({ user }) {
// @ts-expect-error user is not null
if (user.error) {
return false
}
return true
},
},
})