@ethlete/query 0.1.0-next.18 → 0.1.0-next.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2020/lib/auth/auth-provider.types.mjs +1 -1
- package/esm2020/lib/auth/bearer-auth-provider.mjs +29 -6
- package/esm2020/lib/directives/infinity-query.directive.mjs +2 -2
- package/fesm2015/ethlete-query.mjs +37 -12
- package/fesm2015/ethlete-query.mjs.map +1 -1
- package/fesm2020/ethlete-query.mjs +29 -6
- package/fesm2020/ethlete-query.mjs.map +1 -1
- package/lib/auth/auth-provider.types.d.ts +10 -1
- package/lib/auth/bearer-auth-provider.d.ts +2 -0
- package/package.json +1 -1
|
@@ -621,7 +621,8 @@ class BearerAuthProvider {
|
|
|
621
621
|
token: null,
|
|
622
622
|
refreshToken: null,
|
|
623
623
|
});
|
|
624
|
-
const
|
|
624
|
+
const cookieEnabled = _config.refreshConfig?.cookieEnabled ?? true;
|
|
625
|
+
const cookieToken = _config.refreshConfig?.cookieName && cookieEnabled ? getCookie(_config.refreshConfig.cookieName) ?? null : null;
|
|
625
626
|
this._tokens$.next({
|
|
626
627
|
token: _config.token || null,
|
|
627
628
|
refreshToken: _config.refreshConfig?.token || cookieToken || null,
|
|
@@ -650,6 +651,23 @@ class BearerAuthProvider {
|
|
|
650
651
|
deleteCookie(this._config.refreshConfig.cookieName, '/');
|
|
651
652
|
}
|
|
652
653
|
}
|
|
654
|
+
enableCookie() {
|
|
655
|
+
if (!this._config.refreshConfig?.cookieName) {
|
|
656
|
+
throw new Error('No cookie name was provided');
|
|
657
|
+
}
|
|
658
|
+
if (!this.tokens.refreshToken) {
|
|
659
|
+
throw new Error('No refresh token was provided');
|
|
660
|
+
}
|
|
661
|
+
this._config.refreshConfig.cookieEnabled = true;
|
|
662
|
+
setCookie(this._config.refreshConfig.cookieName, this.tokens.refreshToken);
|
|
663
|
+
}
|
|
664
|
+
disableCookie() {
|
|
665
|
+
if (!this._config.refreshConfig?.cookieName) {
|
|
666
|
+
throw new Error('No cookie name was provided');
|
|
667
|
+
}
|
|
668
|
+
this._config.refreshConfig.cookieEnabled = false;
|
|
669
|
+
deleteCookie(this._config.refreshConfig.cookieName, '/');
|
|
670
|
+
}
|
|
653
671
|
_prepareForRefresh() {
|
|
654
672
|
if (!this.tokens.token || !this._config.refreshConfig) {
|
|
655
673
|
return;
|
|
@@ -676,11 +694,15 @@ class BearerAuthProvider {
|
|
|
676
694
|
}
|
|
677
695
|
}
|
|
678
696
|
_refreshQuery() {
|
|
679
|
-
|
|
697
|
+
const currentRefreshToken = this.tokens.refreshToken;
|
|
698
|
+
if (!currentRefreshToken || !this._config.refreshConfig) {
|
|
680
699
|
return;
|
|
681
700
|
}
|
|
682
|
-
const args = this._config.refreshConfig.requestArgsAdapter?.(
|
|
683
|
-
|
|
701
|
+
const args = this._config.refreshConfig.requestArgsAdapter?.({
|
|
702
|
+
token: this.tokens.token,
|
|
703
|
+
refreshToken: currentRefreshToken,
|
|
704
|
+
}) ?? {
|
|
705
|
+
body: { refreshToken: currentRefreshToken },
|
|
684
706
|
};
|
|
685
707
|
const query = this._config.refreshConfig.queryCreator.prepare(args).execute({ skipCache: true });
|
|
686
708
|
this._currentRefreshQuery$.next(query);
|
|
@@ -697,7 +719,8 @@ class BearerAuthProvider {
|
|
|
697
719
|
refreshToken: state.response['refreshToken'],
|
|
698
720
|
});
|
|
699
721
|
}
|
|
700
|
-
|
|
722
|
+
const cookieEnabled = this._config.refreshConfig?.cookieEnabled ?? true;
|
|
723
|
+
if (this._config.refreshConfig?.cookieName && this.tokens.refreshToken && cookieEnabled) {
|
|
701
724
|
setCookie(this._config.refreshConfig.cookieName, this.tokens.refreshToken);
|
|
702
725
|
}
|
|
703
726
|
this._prepareForRefresh();
|
|
@@ -991,7 +1014,7 @@ class InfinityQueryDirective {
|
|
|
991
1014
|
itemsPerPage: null,
|
|
992
1015
|
};
|
|
993
1016
|
this._infinityQueryInstance = null;
|
|
994
|
-
this._destroy$ = inject(DestroyService).destroy$;
|
|
1017
|
+
this._destroy$ = inject(DestroyService, { self: true }).destroy$;
|
|
995
1018
|
this._cdr = inject(ChangeDetectorRef);
|
|
996
1019
|
this._viewContainerRef = inject(ViewContainerRef);
|
|
997
1020
|
this._mainTemplateRef = inject((TemplateRef));
|