aboutsummaryrefslogtreecommitdiffstats
path: root/core/src/twofactor-request-token.ts
blob: 868ceec01e9bcef6d5e03ddfd2e0d718720b5583 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/**
 * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

import { onRequestTokenUpdate } from '@nextcloud/auth'
import { getBaseUrl } from '@nextcloud/router'

document.addEventListener('DOMContentLoaded', () => {
	onRequestTokenUpdate((token) => {
		const cancelLink = window.document.getElementById('cancel-login')
		if (!cancelLink) {
			return
		}

		const href = cancelLink.getAttribute('href')
		if (!href) {
			return
		}

		const parsedHref = new URL(href, getBaseUrl())
		parsedHref.searchParams.set('requesttoken', token)
		cancelLink.setAttribute('href', parsedHref.pathname + parsedHref.search)
	})
})