Refactor admin/client interfaces (edited projectOwnerSession) (#1190)

This commit is contained in:
aadesh18 2026-02-11 19:06:57 -08:00 committed by GitHub
parent ee9912fafb
commit 92087c8a5c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 23 additions and 6 deletions

View File

@ -28,7 +28,7 @@ export type AdminAuthApplicationOptions = ServerAuthApplicationOptions &(
superSecretAdminKey: string,
}
| {
projectOwnerSession: InternalSession,
projectOwnerSession: InternalSession | (() => Promise<string | null>),
}
);

View File

@ -42,7 +42,7 @@ export type ClientInterfaceOptions = {
} & ({
publishableClientKey: string,
} | {
projectOwnerSession: InternalSession,
projectOwnerSession: InternalSession | (() => Promise<string | null>),
});
export class StackClientInterface {
@ -286,8 +286,25 @@ export class StackClientInterface {
*/
let tokenObj = await session.getOrFetchLikelyValidTokens(20_000, null);
let adminSession = "projectOwnerSession" in this.options ? this.options.projectOwnerSession : null;
let adminTokenObj = adminSession ? await adminSession.getOrFetchLikelyValidTokens(20_000, null) : null;
let adminSession: InternalSession | null = null;
let adminTokenObj: { accessToken: AccessToken, refreshToken: RefreshToken | null } | null = null;
if ("projectOwnerSession" in this.options) {
const projectOwnerSession = this.options.projectOwnerSession;
if (typeof projectOwnerSession === 'function') {
const accessTokenString = await projectOwnerSession();
if (accessTokenString) {
const accessToken = AccessToken.createIfValid(accessTokenString);
if (accessToken) {
adminTokenObj = { accessToken, refreshToken: null };
}
}
} else {
adminSession = projectOwnerSession;
adminTokenObj = await projectOwnerSession.getOrFetchLikelyValidTokens(20_000, null);
}
}
// all requests should be dynamic to prevent Next.js caching
await this.options.prepareRequest?.();

View File

@ -33,7 +33,7 @@ export type ServerAuthApplicationOptions = (
readonly secretServerKey: string,
}
| {
readonly projectOwnerSession: InternalSession,
readonly projectOwnerSession: InternalSession | (() => Promise<string | null>),
}
)
);

View File

@ -35,7 +35,7 @@ export type StackAdminAppConstructorOptions<HasTokenStore extends boolean, Proje
& StackServerAppConstructorOptions<HasTokenStore, ProjectId>
& {
superSecretAdminKey?: string,
projectOwnerSession?: InternalSession,
projectOwnerSession?: InternalSession | (() => Promise<string | null>),
}
);