Skip to content

Commit 41e38d7

Browse files
author
gwizz
committed
feat(auth): oauth multi-account failover
1 parent 096e14d commit 41e38d7

File tree

8 files changed

+840
-48
lines changed

8 files changed

+840
-48
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { AsyncLocalStorage } from "async_hooks"
2+
3+
type Store = {
4+
oauthRecordByProvider: Map<string, string>
5+
}
6+
7+
const storage = new AsyncLocalStorage<Store>()
8+
9+
export function getOAuthRecordID(providerID: string): string | undefined {
10+
return storage.getStore()?.oauthRecordByProvider.get(providerID)
11+
}
12+
13+
export function withOAuthRecord<T>(providerID: string, recordID: string, fn: () => T): T {
14+
const current = storage.getStore()
15+
const next: Store = {
16+
oauthRecordByProvider: new Map(current?.oauthRecordByProvider ?? []),
17+
}
18+
next.oauthRecordByProvider.set(providerID, recordID)
19+
20+
return storage.run(next, fn)
21+
}

0 commit comments

Comments
 (0)