Skip to content

Commit 91ae0bd

Browse files
committed
fix: improve permssion prompt
1 parent 694d853 commit 91ae0bd

File tree

5 files changed

+14
-7
lines changed

5 files changed

+14
-7
lines changed

packages/devtools-kit/src/_types/rpc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export interface ServerFunctions {
6464
customTabAction(name: string, action: number): Promise<boolean>
6565
runWizard<T extends WizardActions>(token: string, name: T, ...args: GetWizardArgs<T>): Promise<void>
6666
openInEditor(filepath: string): Promise<boolean>
67-
requestForAuth(info?: string): Promise<void>
67+
requestForAuth(info?: string, origin?: string): Promise<void>
6868
verifyAuthToken(token: string): Promise<boolean>
6969
restartNuxt(hard?: boolean): Promise<void>
7070
installNuxtModule(token: string, name: string, dry?: boolean): Promise<InstallModuleReturn>

packages/devtools/client/components/AuthRequiredPanel.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ onMounted(async () => {
88
}
99
}
1010
if (!isDevAuthed.value)
11-
rpc.requestForAuth()
11+
requestForAuth()
1212
})
1313
1414
const authInput = ref('')

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export async function ensureDevAuthToken() {
5151

5252
export const userAgentInfo = new UAParser(navigator.userAgent).getResult()
5353

54-
async function authConfirmAction() {
54+
export async function requestForAuth() {
5555
const desc = [
5656
userAgentInfo.browser.name,
5757
userAgentInfo.browser.version,
@@ -60,7 +60,12 @@ async function authConfirmAction() {
6060
userAgentInfo.os.version,
6161
userAgentInfo.device.type,
6262
].filter(i => i).join(' ')
63-
rpc.requestForAuth(desc)
63+
return await rpc.requestForAuth(desc, window.location.origin)
64+
}
65+
66+
async function authConfirmAction() {
67+
if (!devAuthToken.value)
68+
requestForAuth()
6469

6570
const result = await Promise.race([
6671
AuthConfirm.start(),

packages/devtools/client/pages/modules/custom-[name].vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ onMounted(() => {
2424
}, 2000)
2525
}
2626
else if (tab.value.requireAuth && !isDevAuthed.value) {
27-
rpc.requestForAuth()
27+
requestForAuth()
2828
}
2929
})
3030
</script>

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,17 @@ export function setupGeneralRPC({ nuxt, options, refresh, openInEditorHooks }: N
149149
logger.info('Restarting Nuxt...')
150150
return nuxt.callHook('restart', { hard })
151151
},
152-
async requestForAuth(info: string) {
152+
async requestForAuth(info: string, origin?: string) {
153153
const token = await getDevAuthToken()
154154

155+
origin ||= `${nuxt.options.devServer.https ? 'https' : 'http'}://${nuxt.options.devServer.host === '::' ? 'localhost' : (nuxt.options.devServer.host || 'localhost')}:${nuxt.options.devServer.port}`
156+
155157
const message = [
156158
`A browser is requesting permissions of ${colors.bold(colors.yellow('writing files and running commands'))} from the DevTools UI.`,
157159
colors.bold(info),
158160
'',
159161
'Please open the following URL in the browser:',
160-
colors.bold(colors.green(`${nuxt.options.devServer.https ? 'https' : 'http'}://${nuxt.options.devServer.host === '::' ? 'localhost' : (nuxt.options.devServer.host || 'localhost')}:${nuxt.options.devServer.port}${ROUTE_AUTH}?token=${token}`)),
162+
colors.bold(colors.green(`${origin}${ROUTE_AUTH}?token=${token}`)),
161163
'',
162164
'Or manually copy and paste the following token:',
163165
colors.bold(colors.cyan(token)),

0 commit comments

Comments
 (0)