mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-04 21:04:37 +08:00
Refactor admin/client interfaces (edited projectOwnerSession) (#1190)
This commit is contained in:
parent
ee9912fafb
commit
92087c8a5c
@ -28,7 +28,7 @@ export type AdminAuthApplicationOptions = ServerAuthApplicationOptions &(
|
||||
superSecretAdminKey: string,
|
||||
}
|
||||
| {
|
||||
projectOwnerSession: InternalSession,
|
||||
projectOwnerSession: InternalSession | (() => Promise<string | null>),
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@ -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?.();
|
||||
|
||||
@ -33,7 +33,7 @@ export type ServerAuthApplicationOptions = (
|
||||
readonly secretServerKey: string,
|
||||
}
|
||||
| {
|
||||
readonly projectOwnerSession: InternalSession,
|
||||
readonly projectOwnerSession: InternalSession | (() => Promise<string | null>),
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
@ -35,7 +35,7 @@ export type StackAdminAppConstructorOptions<HasTokenStore extends boolean, Proje
|
||||
& StackServerAppConstructorOptions<HasTokenStore, ProjectId>
|
||||
& {
|
||||
superSecretAdminKey?: string,
|
||||
projectOwnerSession?: InternalSession,
|
||||
projectOwnerSession?: InternalSession | (() => Promise<string | null>),
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user