Skip to content

Commit a69df5b

Browse files
Merge pull request #19 from RoboVault/feat/cli-qol-fixes
fix logins
2 parents 2aa02d6 + ff3d017 commit a69df5b

File tree

5 files changed

+47
-54
lines changed

5 files changed

+47
-54
lines changed

cli/key/delete.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { spinner } from '../spinner.ts'
2-
import { getSupabaseClient } from '../utils.ts'
2+
import { getSupabaseClientAndLogin } from '../utils.ts'
33

44
export const action = async (key: string) => {
55
spinner(`Deleting key ${key}`)
66

7-
const client = getSupabaseClient()
7+
const { supabase: client } = await getSupabaseClientAndLogin()
88

99
const { error } = await client.functions.invoke('api-key', {
1010
method: 'DELETE',

cli/key/list.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { spinner } from '../spinner.ts'
2-
import { getSupabaseClient } from '../utils.ts'
2+
import { getSupabaseClientAndLogin } from '../utils.ts'
33

44
export const action = async () => {
55
spinner('Fetching API keys')
66

7-
const client = getSupabaseClient()
7+
const { supabase: client } = await getSupabaseClientAndLogin()
88

99
const { data, error } = await client.functions.invoke<{ api_key: string }[]>(
1010
'api-key',

cli/key/new.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { spinner } from '../spinner.ts'
2-
import { getSupabaseClient } from '../utils.ts'
2+
import { getSupabaseClientAndLogin } from '../utils.ts'
33

44
export const action = async () => {
55
spinner('Generating new API key')
6-
const client = getSupabaseClient()
6+
const { supabase: client } = await getSupabaseClientAndLogin()
77

88
const { data, error } = await client.functions.invoke('api-key', {
99
method: 'POST',

cli/remove/mod.ts

+8-22
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { SUPABASE_FUNCTIONS_URL } from '../constants.ts'
2-
import { join, wait } from '../deps.ts'
3-
import { login } from '../login/mod.ts'
4-
import { getSupabaseClient } from '../utils.ts'
2+
import { join } from '../deps.ts'
3+
import { spinner } from '../spinner.ts'
4+
import { getSupabaseClientAndLogin } from '../utils.ts'
55

66
export const action = async (
77
options: { manifest: string },
@@ -11,7 +11,7 @@ export const action = async (
1111

1212
if (dev) return deleteDev(options, directory)
1313

14-
const spinner = wait('Deleting...').start()
14+
spinner('Deleting...')
1515

1616
try {
1717
const { manifest: manifestPath } = options
@@ -36,26 +36,12 @@ export const action = async (
3636
}
3737

3838
// delete package
39-
const supabase = getSupabaseClient()
40-
const sessionRes = await supabase.auth.getSession()
41-
42-
if (!sessionRes.data.session) {
43-
await login({}, supabase)
44-
}
45-
46-
const userRes = await supabase.auth.getUser()
47-
if (userRes.error) {
48-
throw userRes.error
49-
}
50-
51-
if (!sessionRes.data.session) {
52-
throw new Error('Not logged in')
53-
}
39+
const { session } = await getSupabaseClientAndLogin()
5440

5541
const headers = new Headers()
5642
headers.append(
5743
'Authorization',
58-
`Bearer ${sessionRes.data.session.access_token}`,
44+
`Bearer ${session.access_token}`,
5945
)
6046

6147
const deleteRes = await fetch(
@@ -70,9 +56,9 @@ export const action = async (
7056
throw new Error(await deleteRes.text())
7157
}
7258

73-
spinner.succeed('Deleted successfully!')
59+
spinner().succeed('Deleted successfully!')
7460
} catch (error) {
75-
spinner.fail('Deletion failed: ' + error.message)
61+
spinner().fail('Deletion failed: ' + error.message)
7662
console.error(error)
7763
}
7864

cli/start/mod.ts

+33-26
Original file line numberDiff line numberDiff line change
@@ -33,33 +33,40 @@ export const action = async (
3333
}
3434

3535
if (!options.mongoConnection && options.db) {
36-
const cleanup = async () => {
37-
console.log(`\nCleaning up...`)
38-
const stopRes = await $`docker stop ${
39-
containerId.stdout.substring(0, 12)
40-
}`
41-
.stdout('piped')
42-
Deno.exit(stopRes.code)
43-
}
44-
45-
const addSignalToCleanup = (signal: Deno.Signal) => {
46-
try {
47-
Deno.addSignalListener(signal, cleanup)
48-
// deno-lint-ignore no-unused-vars no-empty
49-
} catch (e) {}
36+
try {
37+
const cleanup = async () => {
38+
console.log(`\nCleaning up...`)
39+
const stopRes = await $`docker stop ${
40+
containerId.stdout.substring(0, 12)
41+
}`
42+
.stdout('piped')
43+
Deno.exit(stopRes.code)
44+
}
45+
46+
const addSignalToCleanup = (signal: Deno.Signal) => {
47+
try {
48+
Deno.addSignalListener(signal, cleanup)
49+
// deno-lint-ignore no-unused-vars no-empty
50+
} catch (e) {}
51+
}
52+
53+
addSignalToCleanup('SIGINT')
54+
addSignalToCleanup('SIGHUP')
55+
addSignalToCleanup('SIGTERM')
56+
addSignalToCleanup('SIGQUIT')
57+
addSignalToCleanup('SIGTSTP')
58+
addSignalToCleanup('SIGABRT')
59+
60+
const containerId =
61+
await $`docker run --name arkiver_mongodb -d -p 27017:27017 --env MONGO_INITDB_ROOT_USERNAME=admin --env MONGO_INITDB_ROOT_PASSWORD=password --rm mongo`
62+
.stdout('piped')
63+
await delay(3000) // wait for db to start
64+
} catch (e) {
65+
console.error(
66+
`Failed to start mongodb container: ${e.message}, ${e.stack}`,
67+
)
68+
Deno.exit(1)
5069
}
51-
52-
addSignalToCleanup('SIGINT')
53-
addSignalToCleanup('SIGHUP')
54-
addSignalToCleanup('SIGTERM')
55-
addSignalToCleanup('SIGQUIT')
56-
addSignalToCleanup('SIGTSTP')
57-
addSignalToCleanup('SIGABRT')
58-
59-
const containerId =
60-
await $`docker run --name arkiver_mongodb -d -p 27017:27017 --env MONGO_INITDB_ROOT_USERNAME=admin --env MONGO_INITDB_ROOT_PASSWORD=password --rm mongo`
61-
.stdout('piped')
62-
await delay(3000) // wait for db to start
6370
}
6471

6572
const { manifest: manifestPath } = options

0 commit comments

Comments
 (0)