Skip to content

Commit af4990b

Browse files
committed
Pass onRefreshFailure, onRefresh to the client from provider
Signed-off-by: Mitchell Hynes <[email protected]>
1 parent 4fc0bc0 commit af4990b

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/provider.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,17 @@ export function AuthKitProvider(props: AuthKitProviderProps) {
2525
port,
2626
redirectUri,
2727
children,
28+
onRefresh,
29+
onRefreshFailure,
2830
onRedirectCallback,
2931
refreshBufferInterval,
3032
} = props;
3133
const [client, setClient] = React.useState<Client>(NOOP_CLIENT);
3234
const [state, setState] = React.useState(initialState);
3335

34-
const onRefresh = React.useCallback(
35-
({ user, accessToken, organizationId }: AuthenticationResponse) => {
36+
const handleRefresh = React.useCallback(
37+
(response: AuthenticationResponse) => {
38+
const { user, accessToken, organizationId } = response;
3639
const { role = null, permissions = [] } = getClaims(accessToken);
3740
setState((prev) => {
3841
const next = {
@@ -44,8 +47,9 @@ export function AuthKitProvider(props: AuthKitProviderProps) {
4447
};
4548
return isEquivalentWorkOSSession(prev, next) ? prev : next;
4649
});
50+
onRefresh?.(response);
4751
},
48-
[client],
52+
[client]
4953
);
5054

5155
React.useEffect(() => {
@@ -58,7 +62,8 @@ export function AuthKitProvider(props: AuthKitProviderProps) {
5862
redirectUri,
5963
devMode,
6064
onRedirectCallback,
61-
onRefresh,
65+
onRefresh: handleRefresh,
66+
onRefreshFailure,
6267
refreshBufferInterval,
6368
}).then(async (client) => {
6469
const user = client.getUser();
@@ -95,7 +100,7 @@ export function AuthKitProvider(props: AuthKitProviderProps) {
95100
// poor-man's "deep equality" check
96101
function isEquivalentWorkOSSession(
97102
a: typeof initialState,
98-
b: typeof initialState,
103+
b: typeof initialState
99104
) {
100105
return (
101106
a.user?.updatedAt === b.user?.updatedAt &&

0 commit comments

Comments
 (0)