File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -989,18 +989,19 @@ export const auth = betterAuth({
989989 throw new Error ( `Failed to send reset password email: ${ result . message } ` )
990990 }
991991 } ,
992- /** Runs after `onPasswordReset`; cookie-cached sessions survive until `cookieCache.maxAge`. */
992+ /**
993+ * Re-sweeps sessions after `onPasswordReset`, catching one created while it ran (e.g. a social
994+ * sign-in). Cookie-cached sessions survive until `cookieCache.maxAge`.
995+ */
993996 revokeSessionsOnPasswordReset : true ,
997+ /**
998+ * Sessions go first: OAuth issuance references its session, so once they are deleted no new
999+ * grant can be minted behind the sweep. A failure fails the reset, and the retry from a new
1000+ * link redoes the revocation.
1001+ */
9941002 onPasswordReset : async ( { user : resetUser } , request ) => {
995- try {
996- await revokeUserOAuthGrants ( resetUser . id )
997- } catch ( error ) {
998- // Throwing would skip the session revocation Better Auth runs after this hook.
999- logger . error ( '[onPasswordReset] Failed to revoke OAuth grants' , {
1000- userId : resetUser . id ,
1001- error,
1002- } )
1003- }
1003+ await db . delete ( schema . session ) . where ( eq ( schema . session . userId , resetUser . id ) )
1004+ await revokeUserOAuthGrants ( resetUser . id )
10041005 await recordPasswordResetAudit ( { kind : 'completed' , userId : resetUser . id , request } )
10051006 } ,
10061007 } ,
You can’t perform that action at this time.
0 commit comments