Skip to content

fix/use synchronous call on local storage functions #563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/smart-flies-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@turnkey/sdk-browser": patch
---

Change to use synchronous call on browser local storage
8 changes: 4 additions & 4 deletions packages/sdk-browser/scripts/codegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ export class TurnkeySDKClientBase {
}

attempts += 1;

if (!TERMINAL_ACTIVITY_STATUSES.includes(pollData.activity.status as TActivityStatus)) {
await sleep(pollingDuration);
return pollStatus(activityId);
Expand All @@ -364,7 +364,7 @@ export class TurnkeySDKClientBase {
};

const responseData = await this.request<TBodyType, TResponseType>(url, body) as TActivityResponse;

if (!TERMINAL_ACTIVITY_STATUSES.includes(responseData.activity.status as TActivityStatus)) {
return pollStatus(responseData.activity.id);
}
Expand Down Expand Up @@ -435,7 +435,7 @@ export class TurnkeySDKClientBase {
codeBuffer.push(
`\n\t${methodName} = async (input: SdkApiTypes.${inputType}): Promise<SdkApiTypes.${responseType}> => {
const { organizationId, timestampMs, ...rest } = input;
const session = await getStorageValue(StorageKeys.Session);
const session = getStorageValue(StorageKeys.Session);
return this.command("${endpointPath}", {
parameters: rest,
organizationId: organizationId ?? (session?.organizationId ?? this.config.organizationId),
Expand All @@ -448,7 +448,7 @@ export class TurnkeySDKClientBase {
codeBuffer.push(
`\n\t${methodName} = async (input: SdkApiTypes.${inputType}): Promise<SdkApiTypes.${responseType}> => {
const { organizationId, timestampMs, ...rest } = input;
const session = await getStorageValue(StorageKeys.Session);
const session = getStorageValue(StorageKeys.Session);
return this.activityDecision("${endpointPath}",
{
parameters: rest,
Expand Down
26 changes: 13 additions & 13 deletions packages/sdk-browser/src/__clients__/browser-clients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class TurnkeyBrowserClient extends TurnkeyBaseClient {
expiry: Number(readOnlySessionResult.sessionExpiry),
token: readOnlySessionResult.session,
};
await storeSession(session, this.authClient);
storeSession(session, this.authClient);

return readOnlySessionResult;
};
Expand Down Expand Up @@ -158,7 +158,7 @@ export class TurnkeyBrowserClient extends TurnkeyBaseClient {
token: readOnlySessionResult.session,
};

await storeSession(session, AuthClient.Passkey);
storeSession(session, AuthClient.Passkey);
} else if (sessionType === SessionType.READ_WRITE) {
if (!targetPublicKey) {
throw new Error(
Expand All @@ -185,7 +185,7 @@ export class TurnkeyBrowserClient extends TurnkeyBaseClient {
"You must use an iframe client to refresh a read-write session",
);
}
await storeSession(session, AuthClient.Iframe);
storeSession(session, AuthClient.Iframe);
} else {
throw new Error(`Invalid session type passed: ${sessionType}`);
}
Expand Down Expand Up @@ -226,7 +226,7 @@ export class TurnkeyBrowserClient extends TurnkeyBaseClient {
token: bundle,
};

await storeSession(session, AuthClient.Iframe);
storeSession(session, AuthClient.Iframe);
};

/**
Expand All @@ -245,7 +245,7 @@ export class TurnkeyBrowserClient extends TurnkeyBaseClient {
"You must use an iframe client to log in with a session.",
); //should we default to a "localStorage" client?
}
await storeSession(session, AuthClient.Iframe);
storeSession(session, AuthClient.Iframe);
};

/**
Expand Down Expand Up @@ -278,7 +278,7 @@ export class TurnkeyBrowserClient extends TurnkeyBaseClient {
expiry: Number(readOnlySessionResult.sessionExpiry),
token: readOnlySessionResult.session,
};
await storeSession(session, AuthClient.Passkey);
storeSession(session, AuthClient.Passkey);
// Create a read-write session
} else if (sessionType === SessionType.READ_WRITE) {
if (!targetPublicKey) {
Expand Down Expand Up @@ -307,7 +307,7 @@ export class TurnkeyBrowserClient extends TurnkeyBaseClient {
}
await iframeClient.injectCredentialBundle(session.token!);

await storeSession(session, AuthClient.Iframe);
storeSession(session, AuthClient.Iframe);
} else {
throw new Error(`Invalid session type passed: ${sessionType}`);
}
Expand Down Expand Up @@ -345,7 +345,7 @@ export class TurnkeyBrowserClient extends TurnkeyBaseClient {
expiry: Number(readOnlySessionResult.sessionExpiry),
token: readOnlySessionResult.session,
};
await storeSession(session, AuthClient.Wallet);
storeSession(session, AuthClient.Wallet);
// Create a read-write session
} else if (sessionType === SessionType.READ_WRITE) {
if (!targetPublicKey) {
Expand Down Expand Up @@ -374,7 +374,7 @@ export class TurnkeyBrowserClient extends TurnkeyBaseClient {
}
await iframeClient.injectCredentialBundle(session.token!);

await storeSession(session, AuthClient.Iframe);
storeSession(session, AuthClient.Iframe);
} else {
throw new Error(`Invalid session type passed: ${sessionType}`);
}
Expand Down Expand Up @@ -413,7 +413,7 @@ export class TurnkeyBrowserClient extends TurnkeyBaseClient {
};

// store auth bundle in local storage
await saveSession(readWriteSessionResultWithSession, this.authClient);
saveSession(readWriteSessionResultWithSession, this.authClient);

return readWriteSessionResultWithSession;
} catch (error) {
Expand Down Expand Up @@ -443,7 +443,7 @@ export class TurnkeyBrowserClient extends TurnkeyBaseClient {
sessionExpiry: Date.now() + Number(expirationSeconds) * 1000,
};

await saveSession(readWriteSessionResultWithSession, this.authClient);
saveSession(readWriteSessionResultWithSession, this.authClient);
return true;
} catch (error) {
throw new Error(
Expand Down Expand Up @@ -797,7 +797,7 @@ export class TurnkeyPasskeyClient extends TurnkeyBrowserClient {
organizationId?: string,
): Promise<ReadWriteSession> => {
try {
const session = await getStorageValue(StorageKeys.Session);
const session = getStorageValue(StorageKeys.Session);
organizationId = organizationId ?? session?.organizationId;
userId = userId ?? session?.userId;

Expand Down Expand Up @@ -831,7 +831,7 @@ export class TurnkeyPasskeyClient extends TurnkeyBrowserClient {
const whoAmI = await this.getWhoami();
const expiry = Date.now() + Number(expirationSeconds) * 1000;

await saveSession(
saveSession(
{
organizationId,
organizationName: whoAmI?.organizationName ?? "",
Expand Down
Loading
Loading