Skip to content

Commit 7ae0134

Browse files
committed
improve: add browser compilable check for webauthn
1 parent 367c6a9 commit 7ae0134

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

web/src/components/auth/LoginForm.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,31 @@ export const LoginForm: FC = () => {
6161

6262
const onGoFeishuLogin = () => onGoLogin("feishu");
6363
const onGoDingTalkLogin = () => onGoLogin("dingTalk");
64+
65+
const isWebauthnAvailable = () => {
66+
return !!(
67+
navigator.credentials &&
68+
// @ts-expect-error
69+
navigator.credentials.create &&
70+
// @ts-expect-error
71+
navigator.credentials.get &&
72+
window.PublicKeyCredential
73+
);
74+
};
75+
76+
const isWebauthnConditionalAvailable = () => {
77+
return !!window.PublicKeyCredential?.isConditionalMediationAvailable?.();
78+
};
79+
6480
const onPasskeyLogin = async (conditional?: boolean) => {
81+
if (!isWebauthnAvailable()) {
82+
if (!conditional) toast.error("当前浏览器不支持 webauthn");
83+
return
84+
}
85+
if (conditional && !isWebauthnConditionalAvailable()) {
86+
return
87+
}
88+
6589
try {
6690
const {
6791
data: { data: options },

0 commit comments

Comments
 (0)