Skip to content
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

fix: return after resolve to avoid idb to be recreated #617

Merged
merged 6 commits into from Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/generated/changelog.html
Expand Up @@ -10,6 +10,17 @@
<h1>Agent-JS Changelog</h1>

<section>
<h2>Version X.Y.Z</h2>
<ul>
<li>
bug: auth-client resolves window.open issue in login function in safari due to async
storage call
</li>
<li>
bug: auth-client storage wrapper returns after resolve to avoid idb to be recreated
</li>
</ul>
</ul>
<h2>Version 0.13.2</h2>
<ul>
<li>auth-client avoids localstorage global and can be used in a web worker or nodejs</li>
Expand Down
7 changes: 5 additions & 2 deletions packages/auth-client/src/storage.ts
Expand Up @@ -68,11 +68,14 @@ export class LocalStorage implements AuthClientStorage {
* @see implements {@link AuthClientStorage}
*/
export class IdbStorage implements AuthClientStorage {
// Intializes a KeyVal on first request
// Initializes a KeyVal on first request
private initializedDb: IdbKeyVal | undefined;
get _db(): Promise<IdbKeyVal> {
return new Promise(resolve => {
if (this.initializedDb) resolve(this.initializedDb);
if (this.initializedDb) {
resolve(this.initializedDb);
return;
}
IdbKeyVal.create({ version: DB_VERSION }).then(db => {
this.initializedDb = db;
resolve(db);
Expand Down