feat: add seal auth providers
This commit is contained in:
1 parent
25e4dd7714
commit
d575683c8b
8 files changed
+510
No files matched your search
@@ -0,0 +1,30 @@
|
||||
import ky, { HTTPError, KyInstance } from "ky";
|
||||
import { CorpConfig } from "../config/types.js";
|
||||
import { clearSealToken, getSealSessionForCorp } from "../auth/seal.js";
|
||||
|
||||
export async function createSealClient(corp: CorpConfig): Promise<KyInstance> {
|
||||
const session = await getSealSessionForCorp(corp);
|
||||
|
||||
return ky.create({
|
||||
prefix: session.enterprise.sealUrl,
|
||||
timeout: 30000,
|
||||
headers: {
|
||||
Authorization: `Bearer ${session.token}`
|
||||
},
|
||||
hooks: {
|
||||
beforeError: [
|
||||
async ({ error }) => {
|
||||
if (error instanceof HTTPError && error.response.status === 401) {
|
||||
clearSealToken(corp.id);
|
||||
}
|
||||
const body =
|
||||
error instanceof HTTPError
|
||||
? await error.response.text().catch(() => "")
|
||||
: "";
|
||||
error.message = `${error.message}${body ? `: ${body}` : ""}`;
|
||||
return error;
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user