Skip to content

Commit 7fb9f15

Browse files
committed
fix: final
1 parent 4fececd commit 7fb9f15

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

cli/commands/login.mjs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { getRandomPort } from 'get-port-please'
66
import { listen } from 'listhen'
77
import { withQuery, joinURL } from 'ufo'
88
import { NUXT_HUB_URL } from '../utils.mjs'
9-
import whoami from './whoami.mjs'
109

1110
export default defineCommand({
1211
meta: {
@@ -19,7 +18,10 @@ export default defineCommand({
1918
}
2019
const config = loadConfig()
2120
if (config.token) {
22-
return runCommand(whoami, {})
21+
const user = await $api('/user').catch(() => null)
22+
if (user?.name) {
23+
return consola.info(`Already logged in as \`${user.name}\``)
24+
}
2325
}
2426
// Create server for OAuth flow
2527
let listener
@@ -32,7 +34,11 @@ export default defineCommand({
3234
const token = getQuery(event).token
3335

3436
if (token) {
35-
const user = await $api('/user').catch(() => null)
37+
const user = await $api('/user', {
38+
headers: {
39+
Authorization: `token ${token}`
40+
}
41+
}).catch(() => null)
3642
if (user?.name) {
3743
writeConfig({ token })
3844
consola.success('Authenticated successfully!')

0 commit comments

Comments
 (0)