mirror of
https://github.com/hamster1963/nezha-dash.git
synced 2025-04-24 21:10:45 +08:00
33 lines
918 B
TypeScript
33 lines
918 B
TypeScript
import NextAuth from "next-auth"
|
|
import CredentialsProvider from "next-auth/providers/credentials"
|
|
|
|
import getEnv from "./lib/env-entry"
|
|
|
|
export const { handlers, signIn, signOut, auth } = NextAuth({
|
|
secret: process.env.AUTH_SECRET ?? "this_is_nezha_dash_web_secret",
|
|
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-ignore
|
|
if (user.error) {
|
|
return false
|
|
}
|
|
return true
|
|
},
|
|
},
|
|
})
|