Skip to content

Commit

Permalink
Pass onRefreshFailure, onRefresh to the client from provider
Browse files Browse the repository at this point in the history
Signed-off-by: Mitchell Hynes <[email protected]>
  • Loading branch information
ecumene authored and cmatheson committed Dec 10, 2024
1 parent 4fc0bc0 commit 683107d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ export function AuthKitProvider(props: AuthKitProviderProps) {
port,
redirectUri,
children,
onRefresh,
onRefreshFailure,
onRedirectCallback,
refreshBufferInterval,
} = props;
const [client, setClient] = React.useState<Client>(NOOP_CLIENT);
const [state, setState] = React.useState(initialState);

const onRefresh = React.useCallback(
({ user, accessToken, organizationId }: AuthenticationResponse) => {
const handleRefresh = React.useCallback(
(response: AuthenticationResponse) => {
const { user, accessToken, organizationId } = response;
const { role = null, permissions = [] } = getClaims(accessToken);
setState((prev) => {
const next = {
Expand All @@ -44,6 +47,7 @@ export function AuthKitProvider(props: AuthKitProviderProps) {
};
return isEquivalentWorkOSSession(prev, next) ? prev : next;
});
onRefresh?.(response);
},
[client],
);
Expand All @@ -58,7 +62,8 @@ export function AuthKitProvider(props: AuthKitProviderProps) {
redirectUri,
devMode,
onRedirectCallback,
onRefresh,
onRefresh: handleRefresh,
onRefreshFailure,
refreshBufferInterval,
}).then(async (client) => {
const user = client.getUser();
Expand Down

0 comments on commit 683107d

Please sign in to comment.