forked from hamster1963/nezha-dash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.ts
32 lines (30 loc) · 927 Bytes
/
auth.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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;
},
},
});