FIX: Only check for conditional mediation when needed (#24142)
Some browsers still don't support conditional mediation. This PR fixes issues with: - TOR browser (it doesn't have `PublicKeyCredential` at all) - Firefox 119 (doesn't support conditional mediation) We also need to make sure not to call `isConditionalMediationAvailable` on browsers that don't support the method but support the feature (like Safari on iOS).
This commit is contained in:
parent
73589fa475
commit
e7ed18fdfc
|
@ -19,6 +19,7 @@ import escape from "discourse-common/lib/escape";
|
||||||
import I18n from "discourse-i18n";
|
import I18n from "discourse-i18n";
|
||||||
|
|
||||||
export default class Login extends Component {
|
export default class Login extends Component {
|
||||||
|
@service capabilities;
|
||||||
@service dialog;
|
@service dialog;
|
||||||
@service siteSettings;
|
@service siteSettings;
|
||||||
@service site;
|
@service site;
|
||||||
|
@ -116,6 +117,22 @@ export default class Login extends Component {
|
||||||
@action
|
@action
|
||||||
async passkeyLogin(mediation = "optional") {
|
async passkeyLogin(mediation = "optional") {
|
||||||
try {
|
try {
|
||||||
|
// we need to check isConditionalMediationAvailable for Firefox
|
||||||
|
// without it, Firefox will throw console errors
|
||||||
|
// We cannot do a general check because iOS Safari and Chrome in Selenium quietly support the feature
|
||||||
|
// but they do not support the PublicKeyCredential.isConditionalMediationAvailable() method
|
||||||
|
if (
|
||||||
|
mediation === "conditional" &&
|
||||||
|
this.capabilities.isFirefox &&
|
||||||
|
window.PublicKeyCredential
|
||||||
|
) {
|
||||||
|
const isCMA =
|
||||||
|
// eslint-disable-next-line no-undef
|
||||||
|
await PublicKeyCredential.isConditionalMediationAvailable();
|
||||||
|
if (!isCMA) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
const response = await ajax("/session/passkey/challenge.json");
|
const response = await ajax("/session/passkey/challenge.json");
|
||||||
|
|
||||||
const publicKeyCredential = await getPasskeyCredential(
|
const publicKeyCredential = await getPasskeyCredential(
|
||||||
|
|
|
@ -36,15 +36,9 @@ export default class LocalLoginBody extends Component {
|
||||||
|
|
||||||
@action
|
@action
|
||||||
passkeyConditionalLogin() {
|
passkeyConditionalLogin() {
|
||||||
if (
|
if (this.args.canUsePasskeys) {
|
||||||
// eslint-disable-next-line no-undef
|
this.args.passkeyLogin("conditional");
|
||||||
!PublicKeyCredential.isConditionalMediationAvailable ||
|
|
||||||
!this.args.canUsePasskeys
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.args.passkeyLogin("conditional");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
|
|
Loading…
Reference in New Issue