Skip to content

Commit 010ef86

Browse files
committed
[security]: remove external dependency for loading QR codes for 2FA
1 parent 1f64086 commit 010ef86

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"@types/debounce": "^1.2.0",
6464
"@types/events": "^3.0.0",
6565
"@types/node": "^14.11.10",
66+
"@types/qrcode.react": "^1.0.1",
6667
"@types/query-string": "^6.3.0",
6768
"@types/react": "^16.9.41",
6869
"@types/react-copy-to-clipboard": "^4.3.0",

resources/scripts/components/dashboard/forms/SetupTwoFactorModal.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import tw from 'twin.macro';
1111
import Button from '@/components/elements/Button';
1212
import asModal from '@/hoc/asModal';
1313
import ModalContext from '@/context/ModalContext';
14+
import QRCode from 'qrcode.react';
1415

1516
interface Values {
1617
code: string;
1718
}
1819

1920
const SetupTwoFactorModal = () => {
2021
const [ token, setToken ] = useState('');
21-
const [ loading, setLoading ] = useState(true);
2222
const [ recoveryTokens, setRecoveryTokens ] = useState<string[]>([]);
2323

2424
const { dismiss, setPropOverrides } = useContext(ModalContext);
@@ -108,11 +108,7 @@ const SetupTwoFactorModal = () => {
108108
css={tw`w-64 h-64 rounded`}
109109
/>
110110
:
111-
<img
112-
src={`https://api.qrserver.com/v1/create-qr-code/?size=500x500&data=${token}`}
113-
onLoad={() => setLoading(false)}
114-
css={tw`w-full h-full shadow-none rounded-none`}
115-
/>
111+
<QRCode renderAs={'svg'} value={token} css={tw`w-full h-full shadow-none rounded-none`}/>
116112
}
117113
</div>
118114
</div>
@@ -124,7 +120,6 @@ const SetupTwoFactorModal = () => {
124120
type={'text'}
125121
title={'Code From Authenticator'}
126122
description={'Enter the code from your authenticator device after scanning the QR image.'}
127-
autoFocus={!loading}
128123
/>
129124
</div>
130125
<div css={tw`mt-6 md:mt-0 text-right`}>

yarn.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,13 @@
12281228
version "15.7.1"
12291229
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.1.tgz#f1a11e7babb0c3cad68100be381d1e064c68f1f6"
12301230

1231+
"@types/qrcode.react@^1.0.1":
1232+
version "1.0.1"
1233+
resolved "https://registry.yarnpkg.com/@types/qrcode.react/-/qrcode.react-1.0.1.tgz#0904e7a075a6274a5258f19567b4f64013c159d8"
1234+
integrity sha512-PcVCjpsiT2KFKfJibOgTQtkt0QQT/6GbQUp1Np/hMPhwUzMJ2DRUkR9j7tXN9Q8X06qukw+RbaJ8lJ22SBod+Q==
1235+
dependencies:
1236+
"@types/react" "*"
1237+
12311238
"@types/query-string@^6.3.0":
12321239
version "6.3.0"
12331240
resolved "https://registry.yarnpkg.com/@types/query-string/-/query-string-6.3.0.tgz#b6fa172a01405abcaedac681118e78429d62ea39"

0 commit comments

Comments
 (0)