Skip to content

Commit fad945a

Browse files
committed
feat: allow manually enter the token
1 parent 62136a4 commit fad945a

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

packages/devtools/client/components/AuthRequiredPanel.vue

+27
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,24 @@ onMounted(async () => {
1010
if (!isDevAuthed.value)
1111
rpc.requestForAuth()
1212
})
13+
14+
const authInput = ref('')
15+
const isFailed = ref(false)
16+
17+
async function input() {
18+
const token = authInput.value.trim()
19+
isFailed.value = false
20+
await rpc.verifyAuthToken(token)
21+
.then((result) => {
22+
if (result) {
23+
isDevAuthed.value = true
24+
updateDevAuthToken(token)
25+
}
26+
else {
27+
isFailed.value = true
28+
}
29+
})
30+
}
1331
</script>
1432

1533
<template>
@@ -30,6 +48,15 @@ onMounted(async () => {
3048
Waiting for authorization...
3149
</NButton>
3250
</div>
51+
<p>Or you can manually paste the token here:</p>
52+
<form flex="~ inline gap-2 items-center" @submit.prevent="input">
53+
<NTextInput
54+
v-model="authInput" placeholder="Enter token here"
55+
:n="isFailed ? 'red' : undefined"
56+
@keydown.enter="input"
57+
/>
58+
<NIconButton icon="i-carbon-arrow-right" @click="input" />
59+
</form>
3360
</NCard>
3461
</NPanelGrids>
3562
<template v-else>

packages/devtools/client/composables/dev-auth.ts

+9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const bc = new BroadcastChannel('__nuxt_dev_token__')
99

1010
bc.addEventListener('message', (e) => {
1111
if (e.data.event === 'new-token') {
12+
if (e.data.data === devAuthToken.value)
13+
return
1214
const token = e.data.data
1315
rpc.verifyAuthToken(token)
1416
.then((result) => {
@@ -18,6 +20,13 @@ bc.addEventListener('message', (e) => {
1820
}
1921
})
2022

23+
export function updateDevAuthToken(token: string) {
24+
devAuthToken.value = token
25+
isDevAuthed.value = true
26+
localStorage.setItem('__nuxt_dev_token__', token)
27+
bc.postMessage({ event: 'new-token', data: token })
28+
}
29+
2130
export async function ensureDevAuthToken() {
2231
if (isDevAuthed.value)
2332
return devAuthToken.value!

packages/devtools/src/server-rpc/general.ts

+3
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ export function setupGeneralRPC({ nuxt, options, refresh, openInEditorHooks }: N
159159
'',
160160
'Please open the following URL in the browser:',
161161
c.bold(c.green(`http://localhost:${nuxt.options.devServer.port}${ROUTE_AUTH}?token=${token}`)),
162+
'',
163+
'Or manually copy and paste the following token:',
164+
c.bold(c.cyan(token)),
162165
]
163166

164167
// eslint-disable-next-line no-console

0 commit comments

Comments
 (0)