Skip to content

Commit

Permalink
Merge pull request #9428 from marmelab/allow-custom-providers-refresh…
Browse files Browse the repository at this point in the history
…-token-functions

Allow to pass custom provider types to addRefreshAuth functions
  • Loading branch information
fzaninotto authored Nov 8, 2023
2 parents 6c83335 + 662ae92 commit f030350
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions packages/ra-core/src/auth/addRefreshAuthToAuthProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ import { AuthProvider } from '../types';
*
* const authProvider = addRefreshAuthToAuthProvider(authProvider, refreshAuth);
*/
export const addRefreshAuthToAuthProvider = (
provider: AuthProvider,
export const addRefreshAuthToAuthProvider = <
AuthProviderType extends AuthProvider = AuthProvider
>(
provider: AuthProviderType,
refreshAuth: () => Promise<void>
): AuthProvider => {
): AuthProviderType => {
const proxy = new Proxy(provider, {
get(_, name) {
const shouldIntercept =
Expand Down
8 changes: 5 additions & 3 deletions packages/ra-core/src/auth/addRefreshAuthToDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ import { DataProvider } from '../types';
*
* const dataProvider = addRefreshAuthToDataProvider(jsonServerProvider('http://localhost:3000'), refreshAuth);
*/
export const addRefreshAuthToDataProvider = (
provider: DataProvider,
export const addRefreshAuthToDataProvider = <
DataProviderType extends DataProvider = DataProvider
>(
provider: DataProviderType,
refreshAuth: () => Promise<void>
): DataProvider => {
): DataProviderType => {
const proxy = new Proxy(provider, {
get(_, name) {
return async (...args: any[]) => {
Expand Down

0 comments on commit f030350

Please sign in to comment.