Skip to content

Commit

Permalink
refactor(robo/cli): listen to server for auth url instead of creating…
Browse files Browse the repository at this point in the history
… locally

This now better matches the `deploy` command behavior. Let the auth server say which URL to enter instead of hardcoding.
  • Loading branch information
Pkmmte committed Oct 30, 2024
1 parent 34ef0e8 commit 80d0092
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/proud-hotels-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'robo.js': patch
---

refactor(cli): listen to server for auth url instead of creating locally
6 changes: 2 additions & 4 deletions packages/robo/src/cli/commands/login.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Command } from '../utils/cli-handler.js'
import { env } from '../../core/env.js'
import { logger } from '../../core/logger.js'
import { RoboPlay } from '../../roboplay/client.js'
import { color, composeColors } from '../../core/color.js'
Expand Down Expand Up @@ -33,7 +32,6 @@ async function loginAction(_args: string[], options: LoginCommandOptions) {

// Prepare OAuth session
const oauthSession = await RoboPlay.OAuth.create()
const url = env('roboplay.frontend') + `/auth/cli?token=${oauthSession.token}`
let sessionStatus = oauthSession.status

if (!oauthSession.success) {
Expand All @@ -53,7 +51,7 @@ async function loginAction(_args: string[], options: LoginCommandOptions) {
logger.log(Indent, `${cta} to open your web browser...`)

logger.log('\n' + Indent, color.bold('🔗 Prefer to navigate manually?'))
logger.log(Indent, composeColors(color.underline, color.blue)(url), '\n')
logger.log(Indent, composeColors(color.underline, color.blue)(oauthSession.url), '\n')

const spinner = new Spinner(Indent + ` {{spinner}} Waiting for sign in...`)
spinner.start()
Expand All @@ -63,7 +61,7 @@ async function loginAction(_args: string[], options: LoginCommandOptions) {
spinner.stop()
logger.log('\x1b[2A\x1b[J')
logger.log('\n' + Indent, color.dim('Opening browser...'), '\n')
openBrowser(url)
openBrowser(oauthSession.url)

spinner.start()
})
Expand Down
1 change: 1 addition & 0 deletions packages/robo/src/roboplay/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface OAuthSession {
secret: string
status: OAuthSessionStatus
token: string
url: string
}

export interface Pod {
Expand Down

0 comments on commit 80d0092

Please sign in to comment.