Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: get githubUsername from session token #42

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bun.lockb
Binary file not shown.
7 changes: 3 additions & 4 deletions cli/auth/login/register.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Command } from "commander"
import { cliConfig } from "lib/cli-config"
import { setSessionToken } from "lib/cli-config"
import delay from "delay"
import { getKy } from "lib/registry-api/get-ky"
import type { EndpointResponse } from "lib/registry-api/endpoint-types"
Expand Down Expand Up @@ -63,9 +63,8 @@ export const registerAuthLogin = (program: Command) => {
)
.json()

cliConfig.set("sessionToken", session.token)

console.log("Ready to use!")
setSessionToken(session.token)
console.log("\nReady to use!")
}

// Register the auth login subcommand
Expand Down
4 changes: 2 additions & 2 deletions cli/auth/set-token/register.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Command } from "commander"
import { cliConfig } from "lib/cli-config"
import { setSessionToken } from "lib/cli-config"

function validateJWTLength(token: string) {
const parts = token.split(".")
Expand All @@ -19,7 +19,7 @@ export const registerAuthSetToken = (program: Command) => {
.action((token) => {
if (!validateJWTLength(token))
return console.log("Invalid token provided")
cliConfig.set("sessionToken", token)
setSessionToken(token)
console.log("Token manually updated.")
})
}
9 changes: 9 additions & 0 deletions lib/cli-config/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Configstore from "configstore"
import type { TypedConfigstore } from "./TypedConfigStore"
import { jwtDecode } from "jwt-decode"

export interface CliConfig {
sessionToken?: string
Expand All @@ -11,6 +12,14 @@ export const cliConfig: TypedConfigstore<CliConfig> = new Configstore(
"tscircuit",
)

export const setSessionToken = (token: string) => {
cliConfig.set("sessionToken", token)
const decoded = jwtDecode<{
github_username: string
}>(token)
cliConfig.set("githubUsername", decoded.github_username)
}

export const getRegistryApiUrl = (): string => {
return cliConfig.get("registryApiUrl") ?? "https://registry-api.tscircuit.com"
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"configstore": "^7.0.0",
"cosmiconfig": "^9.0.0",
"delay": "^6.0.0",
"jwt-decode": "^4.0.0",
"ky": "^1.7.4",
"make-vfs": "^1.0.15",
"perfect-cli": "^1.0.20",
Expand Down