fix(core): persist selected console organization
This commit is contained in:
parent
c69abee0c7
commit
745e69634c
1 changed files with 8 additions and 3 deletions
|
|
@ -29,8 +29,12 @@ const Token = Schema.Struct({
|
|||
refresh_token: Schema.String,
|
||||
expires_in: Schema.Number,
|
||||
})
|
||||
const DeviceTokenSuccess = Schema.Struct({
|
||||
...Token.fields,
|
||||
org_id: Schema.String,
|
||||
})
|
||||
const TokenPending = Schema.Struct({ error: Schema.String })
|
||||
const DeviceToken = Schema.Union([Token, TokenPending])
|
||||
const DeviceToken = Schema.Union([DeviceTokenSuccess, TokenPending])
|
||||
const User = Schema.Struct({ id: Schema.String, email: Schema.String })
|
||||
const Org = Schema.Struct({ id: Schema.String, name: Schema.String })
|
||||
|
||||
|
|
@ -261,7 +265,7 @@ function poll(http: HttpClient.HttpClient, server: string, deviceCode: string, i
|
|||
return loop(interval)
|
||||
}
|
||||
|
||||
function credential(http: HttpClient.HttpClient, server: string, token: typeof Token.Type) {
|
||||
function credential(http: HttpClient.HttpClient, server: string, token: typeof DeviceTokenSuccess.Type) {
|
||||
return Effect.gen(function* () {
|
||||
const [user, orgs] = yield* Effect.all(
|
||||
[
|
||||
|
|
@ -270,7 +274,8 @@ function credential(http: HttpClient.HttpClient, server: string, token: typeof T
|
|||
],
|
||||
{ concurrency: 2 },
|
||||
)
|
||||
const org = orgs.toSorted((a, b) => a.name.localeCompare(b.name) || a.id.localeCompare(b.id))[0]
|
||||
const org = orgs.find((org) => org.id === token.org_id)
|
||||
if (!org) return yield* Effect.fail(new Error(`Selected organization ${token.org_id} is not available`))
|
||||
return Credential.OAuth.make({
|
||||
type: "oauth" as const,
|
||||
methodID,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue