Socket
Socket
Sign inDemoInstall

@auth0/auth0-spa-js

Package Overview
Dependencies
Maintainers
45
Versions
89
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@auth0/auth0-spa-js - npm Package Compare versions

Comparing version 1.16.0 to 1.16.1

8

CHANGELOG.md
# Change Log
## [v1.16.1](https://github.com/auth0/auth0-spa-js/tree/v1.16.1) (2021-07-07)
[Full Changelog](https://github.com/auth0/auth0-spa-js/compare/v1.16.0...v1.16.1)
**Fixed**
- Changes to logout and cache synchronicity [\#758](https://github.com/auth0/auth0-spa-js/pull/758) ([stevehobbsdev](https://github.com/stevehobbsdev))
## [v1.16.0](https://github.com/auth0/auth0-spa-js/tree/v1.16.0) (2021-07-05)

@@ -4,0 +12,0 @@

5

dist/typings/Auth0Client.d.ts

@@ -196,2 +196,5 @@ import { Auth0ClientOptions, RedirectLoginOptions, PopupLoginOptions, PopupConfigOptions, GetUserOptions, GetIdTokenClaimsOptions, RedirectLoginResult, GetTokenSilentlyOptions, GetTokenWithPopupOptions, LogoutOptions, CacheLocation, LogoutUrlOptions, User, IdToken } from './global';

* the parameters provided as arguments, to clear the Auth0 session.
*
* **Note:** If you are using a custom cache, and specifying `localOnly: true`, and you want to perform actions or read state from the SDK immediately after logout, you should `await` the result of calling `logout`.
*
* If the `federated` option is specified it also clears the Identity Provider session.

@@ -205,5 +208,5 @@ * If the `localOnly` option is specified, it only clears the application session.

*/
logout(options?: LogoutOptions): void;
logout(options?: LogoutOptions): Promise<void> | void;
private _getTokenFromIFrame;
private _getTokenUsingRefreshToken;
}

8

dist/typings/cache/cache-localstorage.d.ts
import { ICache, Cacheable } from './shared';
export declare class LocalStorageCache implements ICache {
set<T = Cacheable>(key: string, entry: T): Promise<void>;
get<T = Cacheable>(key: string): Promise<T>;
remove(key: string): Promise<void>;
allKeys(): Promise<string[]>;
set<T = Cacheable>(key: string, entry: T): void;
get<T = Cacheable>(key: string): T;
remove(key: string): void;
allKeys(): string[];
}

@@ -9,2 +9,6 @@ import { CacheEntry, ICache, CacheKey } from './shared';

clear(): Promise<void>;
/**
* Note: only call this if you're sure one of our internal (synchronous) caches are being used.
*/
clearSync(): void;
private wrapCacheEntry;

@@ -11,0 +15,0 @@ private getCacheKeys;

@@ -1,2 +0,2 @@

import { ICache, KeyManifestEntry } from './shared';
import { ICache, KeyManifestEntry, MaybePromise } from './shared';
export declare class CacheKeyManifest {

@@ -9,5 +9,5 @@ private cache;

remove(key: string): Promise<void>;
get(): Promise<KeyManifestEntry>;
clear(): Promise<void>;
get(): MaybePromise<KeyManifestEntry>;
clear(): MaybePromise<void>;
private createManifestKeyFrom;
}

@@ -54,8 +54,9 @@ import { IdToken, User } from '../global';

export declare type Cacheable = WrappedCacheEntry | KeyManifestEntry;
export declare type MaybePromise<T> = Promise<T> | T;
export interface ICache {
set<T = Cacheable>(key: string, entry: T): Promise<void>;
get<T = Cacheable>(key: string): Promise<T>;
remove(key: string): Promise<void>;
allKeys?(): Promise<string[]>;
set<T = Cacheable>(key: string, entry: T): MaybePromise<void>;
get<T = Cacheable>(key: string): MaybePromise<T>;
remove(key: string): MaybePromise<void>;
allKeys?(): MaybePromise<string[]>;
}
export {};

@@ -1,2 +0,2 @@

declare const _default: "1.16.0";
declare const _default: "1.16.1";
export default _default;

@@ -6,3 +6,3 @@ {

"license": "MIT",
"version": "1.16.0",
"version": "1.16.1",
"main": "dist/lib/auth0-spa-js.cjs.js",

@@ -9,0 +9,0 @@ "types": "dist/typings/index.d.ts",

@@ -219,10 +219,10 @@ # @auth0/auth0-spa-js

The object should implement the following functions:
The object should implement the following functions. Note that all of these functions can optionally return a Promise or a static value.
| Signature | Description |
| ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `async get(key)` | Returns the item from the cache with the specified key, or `undefined` if it was not found |
| `async set(key: string, object: any): Promise<void>` | Sets an item into the cache |
| `async remove(key)` | Removes a single item from the cache at the specified key, or no-op if the item was not found |
| `async allKeys()` | (optional) Implement this if your cache has the ability to return a list of all keys. Otherwise, the SDK internally records its own key manifest using your cache. **Note**: if you only want to ensure you only return keys used by this SDK, the keys we use are prefixed with `@@auth0spajs@@` |
| Signature | Return type | Description |
| -------------------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `get(key)` | Promise<object> or object | Returns the item from the cache with the specified key, or `undefined` if it was not found |
| `set(key: string, object: any) ` | Promise<void> or void | Sets an item into the cache |
| `remove(key)` | Promise<void> or void | Removes a single item from the cache at the specified key, or no-op if the item was not found |
| `allKeys()` | Promise<string[]> or string [] | (optional) Implement this if your cache has the ability to return a list of all keys. Otherwise, the SDK internally records its own key manifest using your cache. **Note**: if you only want to ensure you only return keys used by this SDK, the keys we use are prefixed with `@@auth0spajs@@` |

@@ -234,3 +234,3 @@ Here's an example of a custom cache implementation that uses `sessionStorage` to store tokens and apply it to the Auth0 SPA SDK:

get: function (key) {
return Promise.resolve(JSON.parse(sessionStorage.getItem(key)));
return JSON.parse(sessionStorage.getItem(key));
},

@@ -240,3 +240,2 @@

sessionStorage.setItem(key, JSON.stringify(value));
return Promise.resolve();
},

@@ -246,3 +245,2 @@

sessionStorage.removeItem(key);
return Promise.resolve();
},

@@ -252,3 +250,3 @@

allKeys: function () {
return Promise.resolve(Object.keys(sessionStorage));
return Object.keys(sessionStorage);
}

@@ -255,0 +253,0 @@ };

@@ -836,2 +836,5 @@ import Lock from 'browser-tabs-lock';

* the parameters provided as arguments, to clear the Auth0 session.
*
* **Note:** If you are using a custom cache, and specifying `localOnly: true`, and you want to perform actions or read state from the SDK immediately after logout, you should `await` the result of calling `logout`.
*
* If the `federated` option is specified it also clears the Identity Provider session.

@@ -845,3 +848,3 @@ * If the `localOnly` option is specified, it only clears the application session.

*/
public logout(options: LogoutOptions = {}) {
public logout(options: LogoutOptions = {}): Promise<void> | void {
const { localOnly, ...logoutOptions } = options;

@@ -855,12 +858,20 @@

this.cacheManager.clear();
this.cookieStorage.remove('auth0.is.authenticated');
const postCacheClear = () => {
this.cookieStorage.remove('auth0.is.authenticated');
if (localOnly) {
return;
}
if (localOnly) {
return;
}
const url = this.buildLogoutUrl(logoutOptions);
const url = this.buildLogoutUrl(logoutOptions);
window.location.assign(url);
window.location.assign(url);
};
if (this.options.cache) {
return this.cacheManager.clear().then(() => postCacheClear());
} else {
this.cacheManager.clearSync();
postCacheClear();
}
}

@@ -867,0 +878,0 @@

import { ICache, Cacheable, CACHE_KEY_PREFIX } from './shared';
export class LocalStorageCache implements ICache {
public set<T = Cacheable>(key: string, entry: T): Promise<void> {
public set<T = Cacheable>(key: string, entry: T) {
localStorage.setItem(key, JSON.stringify(entry));
return Promise.resolve();
}
public get<T = Cacheable>(key: string): Promise<T> {
public get<T = Cacheable>(key: string) {
const json = window.localStorage.getItem(key);
if (!json) return Promise.resolve(null);
if (!json) return;
try {
const payload = JSON.parse(json);
return Promise.resolve(payload);
const payload = JSON.parse(json) as T;
return payload;
} catch (e) {
/* istanbul ignore next */
return Promise.resolve(null);
return;
}
}
public remove(key: string): Promise<void> {
public remove(key: string) {
localStorage.removeItem(key);
return Promise.resolve();
}
public allKeys(): Promise<string[]> {
return Promise.resolve(
Object.keys(window.localStorage).filter(key =>
key.startsWith(CACHE_KEY_PREFIX)
)
public allKeys() {
return Object.keys(window.localStorage).filter(key =>
key.startsWith(CACHE_KEY_PREFIX)
);
}
}

@@ -93,2 +93,16 @@ import { CacheKeyManifest } from './key-manifest';

/**
* Note: only call this if you're sure one of our internal (synchronous) caches are being used.
*/
clearSync(): void {
const keys = this.cache.allKeys() as string[];
/* istanbul ignore next */
if (!keys) return;
keys.forEach(key => {
this.cache.remove(key);
});
}
private wrapCacheEntry(entry: CacheEntry): WrappedCacheEntry {

@@ -95,0 +109,0 @@ const expiresInTime = Math.floor(Date.now() / 1000) + entry.expires_in;

@@ -8,24 +8,22 @@ import { Cacheable, ICache } from './shared';

return {
set<T = Cacheable>(key: string, entry: T): Promise<void> {
set<T = Cacheable>(key: string, entry: T) {
cache[key] = entry;
return Promise.resolve();
},
get<T = Cacheable>(key: string): Promise<T> {
get<T = Cacheable>(key: string) {
const cacheEntry = cache[key] as T;
if (!cacheEntry) {
return Promise.resolve(null);
return;
}
return Promise.resolve(cacheEntry);
return cacheEntry;
},
remove(key: string): Promise<void> {
remove(key: string) {
delete cache[key];
return Promise.resolve();
},
allKeys(): Promise<string[]> {
return Promise.resolve(Object.keys(cache));
allKeys(): string[] {
return Object.keys(cache);
}

@@ -32,0 +30,0 @@ };

@@ -1,2 +0,7 @@

import { CACHE_KEY_PREFIX, ICache, KeyManifestEntry } from './shared';
import {
CACHE_KEY_PREFIX,
ICache,
KeyManifestEntry,
MaybePromise
} from './shared';

@@ -37,7 +42,7 @@ export class CacheKeyManifest {

get(): Promise<KeyManifestEntry> {
get(): MaybePromise<KeyManifestEntry> {
return this.cache.get<KeyManifestEntry>(this.manifestKey);
}
clear(): Promise<void> {
clear(): MaybePromise<void> {
return this.cache.remove(this.manifestKey);

@@ -44,0 +49,0 @@ }

@@ -84,7 +84,9 @@ import { IdToken, User } from '../global';

export type MaybePromise<T> = Promise<T> | T;
export interface ICache {
set<T = Cacheable>(key: string, entry: T): Promise<void>;
get<T = Cacheable>(key: string): Promise<T>;
remove(key: string): Promise<void>;
allKeys?(): Promise<string[]>;
set<T = Cacheable>(key: string, entry: T): MaybePromise<void>;
get<T = Cacheable>(key: string): MaybePromise<T>;
remove(key: string): MaybePromise<void>;
allKeys?(): MaybePromise<string[]>;
}

@@ -1,1 +0,1 @@

export default '1.16.0';
export default '1.16.1';

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc