Skip to content

Commit 8ffe9db

Browse files
committed
🚑️ 🔒 Refactor password check logic: streamline conditions for password handling in auth flow
1 parent c35db02 commit 8ffe9db

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ yarn-error.log*
3636
*.njsproj
3737
*.sln
3838
*.sw*
39+
40+
CHANGELOG.md

client/src/helper/auth.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export const initializeAuth = async () => {
1111
const { canBeReset, allowPassword, havePassword, needPassword } = (await checkPassword()) as any
1212
isResettable.set(canBeReset)
1313
isAuthenticated.set(!needPassword)
14-
/* 「设置探矿」密码区展示条件:允许开启密码 || 已经设置密码 */
1514
isPasswordAllowed.set(allowPassword || havePassword)
1615
} catch (error) {
1716
console.error('Failed to check password status:', error)

server/src/controllers/password.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ import { createSession, validateSession } from '../models/session'
55
export const checkPassword = async (request: FastifyRequest) => {
66
const canBeReset = process.env.CAN_BE_RESET === 'true'
77
const allowPassword = process.env.ALLOW_PASSWORD === 'true'
8-
98
const havePassword = !!(await Password.findOne({ where: {} }))
9+
10+
if (!allowPassword) {
11+
return { allowPassword, needPassword: false, havePassword, canBeReset }
12+
}
13+
1014
const sessionId = request.cookies.sessionId
1115
if (sessionId) {
1216
const isValid = await validateSession(sessionId)

0 commit comments

Comments
 (0)