Skip to content

Commit

Permalink
fix: require token for restartNuxt
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Nov 27, 2023
1 parent 69316c4 commit 09384af
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
8 changes: 5 additions & 3 deletions packages/devtools-kit/src/_types/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@ export interface ServerFunctions {
customTabAction(name: string, action: number): Promise<boolean>
runWizard<T extends WizardActions>(token: string, name: T, ...args: GetWizardArgs<T>): Promise<void>
openInEditor(filepath: string): Promise<boolean>
requestForAuth(info?: string, origin?: string): Promise<void>
verifyAuthToken(token: string): Promise<boolean>
restartNuxt(hard?: boolean): Promise<void>
restartNuxt(token: string, hard?: boolean): Promise<void>
installNuxtModule(token: string, name: string, dry?: boolean): Promise<InstallModuleReturn>
uninstallNuxtModule(token: string, name: string, dry?: boolean): Promise<InstallModuleReturn>
enableTimeline(dry: boolean): Promise<[string, string]>

// Dev Token
requestForAuth(info?: string, origin?: string): Promise<void>
verifyAuthToken(token: string): Promise<boolean>
}

export interface ClientFunctions {
Expand Down
1 change: 1 addition & 0 deletions packages/devtools/client/components/AssetDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const codeSnippets = computed(() => {
})
const copy = useCopy()
const openInEditor = useOpenInEditor()
const timeAgo = useTimeAgo(() => asset.value.mtime)
const fileSize = computed(() => {
const size = asset.value.size
Expand Down
4 changes: 2 additions & 2 deletions packages/devtools/client/components/RestartDialogs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ nuxt.hook('devtools:terminal:exit', ({ id, code }) => {
state.value = state.value.filter(dialog => dialog.id !== id)
PromiseConfirm
.start(dialog.message)
.then((result) => {
.then(async (result) => {
if (result) {
rpc.restartNuxt()
rpc.restartNuxt(await ensureDevAuthToken())
setTimeout(() => {
client.value?.app.reload()
}, 500)
Expand Down
2 changes: 1 addition & 1 deletion packages/devtools/client/composables/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function getPackageUpdate(name: string, options?: NpmCommandOptions) {
async function restart() {
if (state.value !== 'updated')
return
await rpc.restartNuxt()
await rpc.restartNuxt(await ensureDevAuthToken())
}

return {
Expand Down
11 changes: 9 additions & 2 deletions packages/devtools/src/server-rpc/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ import type { AutoImportsWithMetadata, HookInfo, NuxtDevtoolsServerContext, Serv
import { setupHooksDebug } from '../runtime/shared/hooks'
import { getDevAuthToken } from '../dev-auth'

export function setupGeneralRPC({ nuxt, options, refresh, openInEditorHooks }: NuxtDevtoolsServerContext) {
export function setupGeneralRPC({
nuxt,
options,
refresh,
ensureDevAuthToken,
openInEditorHooks,
}: NuxtDevtoolsServerContext) {
const components: Component[] = []
const imports: Import[] = []
const importPresets: Import[] = []
Expand Down Expand Up @@ -183,7 +189,8 @@ export function setupGeneralRPC({ nuxt, options, refresh, openInEditorHooks }: N
return false
}
},
restartNuxt(hard = true) {
async restartNuxt(token: string, hard = true) {
await ensureDevAuthToken(token)
logger.info('Restarting Nuxt...')
return nuxt.callHook('restart', { hard })
},
Expand Down

0 comments on commit 09384af

Please sign in to comment.