Skip to content

Commit 3974075

Browse files
committed
fix: pass credential request options as a prop
To prevent a DataCloneError caused by Pinia's reactive Proxy. Assisted-by: ClaudeCode:claude-sonnet-5 Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
1 parent eb560b9 commit 3974075

4 files changed

Lines changed: 35 additions & 14 deletions

File tree

‎src/components/Challenge.vue‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@
4949
import { NcButton } from '@nextcloud/vue'
5050
import { browserSupportsWebAuthn, startAuthentication } from '@simplewebauthn/browser'
5151
import logger from '../logger.js'
52-
import { mapState } from 'pinia'
53-
import { useMainStore } from '../store.js'
5452
5553
export default {
5654
name: 'Challenge',
@@ -59,6 +57,13 @@ export default {
5957
NcButton,
6058
},
6159
60+
props: {
61+
credentialRequestOptions: {
62+
type: Object,
63+
required: true,
64+
},
65+
},
66+
6267
data() {
6368
return {
6469
challenge: '',
@@ -67,7 +72,6 @@ export default {
6772
},
6873
6974
computed: {
70-
...mapState(useMainStore, ['credentialRequestOptions']),
7175
httpWarning() {
7276
return document.location.protocol !== 'https:'
7377
},

‎src/main-challenge.js‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,12 @@
44
*/
55

66
import { createApp } from 'vue'
7-
import { createPinia } from 'pinia'
87
import Nextcloud from './mixins/Nextcloud.js'
98
import Challenge from './components/Challenge.vue'
109
import { loadState } from '@nextcloud/initial-state'
11-
import { useMainStore } from './store.js'
12-
13-
const pinia = createPinia()
1410

1511
const credentialRequestOptions = loadState('twofactor_webauthn', 'credential-request-options')
16-
const mainStore = useMainStore(pinia)
17-
mainStore.$patch({
18-
credentialRequestOptions,
19-
})
2012

21-
const app = createApp(Challenge)
13+
const app = createApp(Challenge, { credentialRequestOptions })
2214
app.mixin(Nextcloud)
23-
app.use(pinia)
2415
app.mount('#twofactor-webauthn-challenge')

‎src/store.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import * as RegistrationService from './services/RegistrationService.js'
88

99
export const useMainStore = defineStore('main', {
1010
state: () => ({
11-
credentialRequestOptions: {},
1211
devices: [],
1312
}),
1413
actions: {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import { shallowMount } from '@vue/test-utils'
7+
import Nextcloud from '../../../mixins/Nextcloud.js'
8+
import Challenge from '../../../components/Challenge.vue'
9+
10+
describe('Challenge', () => {
11+
it('receives credentialRequestOptions as a prop', () => {
12+
const credentialRequestOptions = {
13+
allowCredentials: [{ id: 'abc', transports: ['usb'] }],
14+
}
15+
16+
const challenge = shallowMount(Challenge, {
17+
global: {
18+
mixins: [Nextcloud],
19+
},
20+
props: {
21+
credentialRequestOptions,
22+
},
23+
})
24+
25+
expect(challenge.vm.credentialRequestOptions).to.deep.equal(credentialRequestOptions)
26+
})
27+
})

0 commit comments

Comments
 (0)