Skip to content

Commit

Permalink
destructure config within sdk core instead of using rest operator
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeLo123 committed Sep 20, 2024
1 parent aa4827b commit 630bffe
Showing 1 changed file with 45 additions and 6 deletions.
51 changes: 45 additions & 6 deletions packages/sdk-react/src/components/providers/FusionAuthProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
useRef,
} from 'react';

import { SDKCore } from '@fusionauth-sdk/core';
import { SDKConfig, SDKCore } from '@fusionauth-sdk/core';

import { FusionAuthProviderConfig } from './FusionAuthProviderConfig';
import {
Expand All @@ -18,10 +18,49 @@ import {
import { FusionAuthContext, UserInfo as DefaultUserInfo } from './Context';
import { FusionAuthProviderContext } from './FusionAuthProviderContext';

function FusionAuthProvider<T = DefaultUserInfo>({
children,
...config
}: PropsWithChildren & FusionAuthProviderConfig) {
function FusionAuthProvider<T = DefaultUserInfo>(
props: PropsWithChildren & FusionAuthProviderConfig,
) {
const config: Omit<SDKConfig, 'cookieAdapter' | 'onTokenExpiration'> =
useMemo(
() => ({
serverUrl: props.serverUrl,
clientId: props.clientId,
redirectUri: props.redirectUri,
scope: props.scope,
postLogoutRedirectUri: props.postLogoutRedirectUri,
shouldAutoRefresh: props.shouldAutoRefresh,
shouldAutoFetchUserInfo: props.shouldAutoFetchUserInfo,
autoRefreshSecondsBeforeExpiry: props.autoRefreshSecondsBeforeExpiry,
onRedirect: props.onRedirect,
loginPath: props.loginPath,
logoutPath: props.logoutPath,
registerPath: props.registerPath,
tokenRefreshPath: props.tokenRefreshPath,
mePath: props.mePath,
accessTokenExpireCookieName: props.accessTokenExpireCookieName,
onAutoRefreshFailure: props.onAutoRefreshFailure,
}),
[
props.serverUrl,
props.clientId,
props.redirectUri,
props.scope,
props.postLogoutRedirectUri,
props.shouldAutoRefresh,
props.shouldAutoFetchUserInfo,
props.autoRefreshSecondsBeforeExpiry,
props.onRedirect,
props.loginPath,
props.logoutPath,
props.registerPath,
props.tokenRefreshPath,
props.mePath,
props.accessTokenExpireCookieName,
props.onAutoRefreshFailure,
],
);

const cookieAdapter = useCookieAdapter(config);

const coreRef = useRef<SDKCore>();
Expand Down Expand Up @@ -70,7 +109,7 @@ function FusionAuthProvider<T = DefaultUserInfo>({

return (
<FusionAuthContext.Provider value={providerValue}>
{children}
{props.children}
</FusionAuthContext.Provider>
);
}
Expand Down

0 comments on commit 630bffe

Please sign in to comment.