-
Notifications
You must be signed in to change notification settings - Fork 789
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
b6980c9
commit ba4ea6e
Showing
3 changed files
with
44 additions
and
37 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
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,23 +1,32 @@ | ||
import NextAuth from "next-auth"; | ||
import Credentials from "next-auth/providers/credentials"; | ||
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, | ||
pages: { | ||
signIn: "/", | ||
}, | ||
providers: [ | ||
Credentials({ | ||
CredentialsProvider({ | ||
type: "credentials", | ||
credentials: { password: { label: "Password", type: "password" } }, | ||
authorize: async (credentials) => { | ||
if (credentials.password === getEnv("SitePassword")) { | ||
// authorization function | ||
async authorize(credentials) { | ||
const { password } = credentials; | ||
if (password === getEnv("SitePassword")) { | ||
return { id: "nezha-dash-auth" }; | ||
} | ||
return null; | ||
return { error: "Invalid password" }; | ||
}, | ||
}), | ||
], | ||
callbacks: { | ||
async signIn({ user }) { | ||
// @ts-ignore | ||
if (user.error) { | ||
return false; | ||
} | ||
return true; | ||
}, | ||
}, | ||
}); |
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