···127127 return e.Where(cond)
128128 }
129129130130- // 2fa filter uses LEFT JOIN to check whether a user has a 2fa record
131131- // While using LEFT JOIN, sometimes the performance might not be good, but it won't be a problem now, such SQL is seldom executed.
132132- // There are some possible methods to refactor this SQL in future when we really need to optimize the performance (but not now):
133133- // (1) add a column in user table (2) add a setting value in user_setting table (3) use search engines (bleve/elasticsearch)
130130+ // Check if the user has two factor enabled, which is TOTP or Webauthn.
134131 if opts.IsTwoFactorEnabled.Value() {
135135- cond = cond.And(builder.Expr("two_factor.uid IS NOT NULL"))
132132+ cond = cond.And(builder.Expr("two_factor.uid IS NOT NULL OR webauthn_credential.user_id IS NOT NULL"))
136133 } else {
137137- cond = cond.And(builder.Expr("two_factor.uid IS NULL"))
134134+ cond = cond.And(builder.Expr("two_factor.uid IS NULL AND webauthn_credential.user_id IS NULL"))
138135 }
139136140137 return e.Join("LEFT OUTER", "two_factor", "two_factor.uid = `user`.id").
138138+ Join("LEFT OUTER", "webauthn_credential", "webauthn_credential.user_id = `user`.id").
141139 Where(cond)
142140}
143141