File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed
packages/better-auth/src/plugins/two-factor Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -132,7 +132,7 @@ export const backupCode2fa = (
132132 ctx . context . secret ,
133133 ) ;
134134 if ( ! validate . status ) {
135- throw new APIError ( "BAD_REQUEST " , {
135+ throw new APIError ( "UNAUTHORIZED " , {
136136 message : "Invalid backup code" ,
137137 } ) ;
138138 }
Original file line number Diff line number Diff line change @@ -218,6 +218,21 @@ describe("two factor", async () => {
218218 } ) ;
219219 expect ( currentBackupCodes . backupCodes ) . toBeDefined ( ) ;
220220 expect ( currentBackupCodes . backupCodes ) . not . toContain ( backupCode ) ;
221+
222+ const res = await client . twoFactor . verifyBackupCode ( {
223+ code : "invalid-code" ,
224+ fetchOptions : {
225+ headers,
226+ onSuccess ( context ) {
227+ const parsed = parseSetCookieHeader (
228+ context . response . headers . get ( "Set-Cookie" ) || "" ,
229+ ) ;
230+ const token = parsed . get ( "better-auth.session_token" ) ?. value ;
231+ expect ( token ?. length ) . toBeGreaterThan ( 0 ) ;
232+ } ,
233+ } ,
234+ } ) ;
235+ expect ( res . error ?. message ) . toBe ( "Invalid backup code" ) ;
221236 } ) ;
222237
223238 it ( "should trust device" , async ( ) => {
You can’t perform that action at this time.
0 commit comments