|
1 | | -import { devtoolsUiShowNotification } from '#imports' |
2 | | -import { until } from '@vueuse/core' |
3 | 1 | import { parseUA } from 'ua-parser-modern' |
4 | 2 | import { ref } from 'vue' |
5 | | -import { AuthConfirm } from './dialog' |
6 | | -import { rpc } from './rpc' |
7 | 3 |
|
8 | | -export const devAuthToken = ref<string | null>(localStorage.getItem('__nuxt_dev_token__')) |
| 4 | +/** @deprecated Auth is now handled by Vite DevTools */ |
| 5 | +export const devAuthToken = ref<string | null>('disabled') |
9 | 6 |
|
10 | | -export const isDevAuthed = ref(false) |
| 7 | +/** @deprecated Auth is now handled by Vite DevTools */ |
| 8 | +export const isDevAuthed = ref(true) |
11 | 9 |
|
12 | | -const bc = new BroadcastChannel('__nuxt_dev_token__') |
13 | | - |
14 | | -bc.addEventListener('message', (e) => { |
15 | | - if (e.data.event === 'new-token') { |
16 | | - if (e.data.data === devAuthToken.value) |
17 | | - return |
18 | | - const token = e.data.data |
19 | | - rpc.verifyAuthToken(token) |
20 | | - .then((result) => { |
21 | | - devAuthToken.value = result ? token : null |
22 | | - isDevAuthed.value = result |
23 | | - }) |
24 | | - } |
25 | | -}) |
26 | | - |
27 | | -export function updateDevAuthToken(token: string) { |
28 | | - devAuthToken.value = token |
29 | | - isDevAuthed.value = true |
30 | | - localStorage.setItem('__nuxt_dev_token__', token) |
31 | | - bc.postMessage({ event: 'new-token', data: token }) |
| 10 | +/** @deprecated Auth is now handled by Vite DevTools */ |
| 11 | +export function updateDevAuthToken(_token: string) { |
| 12 | + console.warn('[nuxt-devtools] `updateDevAuthToken` is deprecated. Auth is now handled by Vite DevTools.') |
32 | 13 | } |
33 | 14 |
|
| 15 | +/** @deprecated Auth is now handled by Vite DevTools */ |
34 | 16 | export async function ensureDevAuthToken() { |
35 | | - if (isDevAuthed.value) |
36 | | - return devAuthToken.value! |
37 | | - |
38 | | - if (!devAuthToken.value) |
39 | | - await authConfirmAction() |
40 | | - |
41 | | - isDevAuthed.value = await rpc.verifyAuthToken(devAuthToken.value!) |
42 | | - if (!isDevAuthed.value) { |
43 | | - devAuthToken.value = null |
44 | | - devtoolsUiShowNotification({ |
45 | | - message: 'Invalid auth token, action canceled', |
46 | | - icon: 'i-carbon-warning-alt', |
47 | | - classes: 'text-red', |
48 | | - }) |
49 | | - await authConfirmAction() |
50 | | - throw new Error('[Nuxt DevTools] Invalid auth token') |
51 | | - } |
52 | | - |
53 | | - return devAuthToken.value! |
| 17 | + console.warn('[nuxt-devtools] `ensureDevAuthToken` is deprecated. Auth is now handled by Vite DevTools.') |
| 18 | + return '' |
54 | 19 | } |
55 | 20 |
|
56 | 21 | export const userAgentInfo = parseUA(navigator.userAgent) |
57 | 22 |
|
| 23 | +/** @deprecated Auth is now handled by Vite DevTools */ |
58 | 24 | export async function requestForAuth() { |
59 | | - const desc = [ |
60 | | - userAgentInfo.browser.name, |
61 | | - userAgentInfo.browser.version, |
62 | | - '|', |
63 | | - userAgentInfo.os.name, |
64 | | - userAgentInfo.os.version, |
65 | | - userAgentInfo.device.type, |
66 | | - ].filter(i => i).join(' ') |
67 | | - return await rpc.requestForAuth(desc, window.location.origin) |
68 | | -} |
69 | | - |
70 | | -async function authConfirmAction() { |
71 | | - if (!devAuthToken.value) |
72 | | - requestForAuth() |
73 | | - |
74 | | - const result = await Promise.race([ |
75 | | - AuthConfirm.start(), |
76 | | - until(devAuthToken.value).toBeTruthy(), |
77 | | - ]) |
78 | | - |
79 | | - if (result === false) { |
80 | | - // @unocss-include |
81 | | - devtoolsUiShowNotification({ |
82 | | - message: 'Action canceled', |
83 | | - icon: 'carbon-close', |
84 | | - classes: 'text-orange', |
85 | | - }) |
86 | | - throw new Error('[Nuxt DevTools] User canceled auth') |
87 | | - } |
| 25 | + console.warn('[nuxt-devtools] `requestForAuth` is deprecated. Auth is now handled by Vite DevTools.') |
88 | 26 | } |
0 commit comments