@@ -8,7 +8,7 @@ import { normalize, Options } from "../common/util"
8
8
import { AuthType , DefaultedArgs } from "./cli"
9
9
import { commit , rootPath } from "./constants"
10
10
import { Heart } from "./heart"
11
- import { isHashMatch } from "./util"
11
+ import { getPasswordMethod , handlePasswordValidation , IsCookieValidArgs , isCookieValid , isHashMatch } from "./util"
12
12
13
13
declare global {
14
14
// eslint-disable-next-line @typescript-eslint/no-namespace
@@ -68,14 +68,16 @@ export const authenticated = async (req: express.Request): Promise<boolean> => {
68
68
return true
69
69
case AuthType . Password :
70
70
// The password is stored in the cookie after being hashed.
71
- // TODO@jsjoeio this also needs to be refactored to check if they're using the legacy password
72
- // or the new one. we can't assume hashed-password means legacy
73
- return ! ! (
74
- req . cookies . key &&
75
- ( req . args [ "hashed-password" ]
76
- ? safeCompare ( req . cookies . key , req . args [ "hashed-password" ] )
77
- : req . args . password && ( await isHashMatch ( req . args . password , req . cookies . key ) ) )
78
- )
71
+ const hashedPasswordFromArgs = req . args [ "hashed-password" ]
72
+ const passwordMethod = getPasswordMethod ( hashedPasswordFromArgs )
73
+ const isCookieValidArgs : IsCookieValidArgs = {
74
+ passwordMethod,
75
+ cookieKey : req . cookies . key as string ,
76
+ passwordFromArgs : req . args . password || "" ,
77
+ hashedPasswordFromArgs : req . args [ "hashed-password" ] ,
78
+ }
79
+
80
+ return await isCookieValid ( isCookieValidArgs )
79
81
default :
80
82
throw new Error ( `Unsupported auth type ${ req . args . auth } ` )
81
83
}
0 commit comments