Skip to content

Commit

Permalink
revalidate token on expire
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-tey committed Dec 24, 2024
1 parent 9d57df0 commit 5b7f35a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ export function ReferralsPageClient() {
const { data: session, status } = useSession();
const referralLinkId = session?.user?.["referralLinkId"];

const { data: { publicToken } = {}, isLoading } = useSWRImmutable<{
const {
data: { publicToken } = {},
isLoading,
mutate,
} = useSWRImmutable<{
publicToken: string;
}>(referralLinkId && "/api/user/embed-tokens", fetcher, {
keepPreviousData: true,
Expand Down Expand Up @@ -43,5 +47,11 @@ export function ReferralsPageClient() {
);
}

return <DubWidget token={publicToken} variant="inline" />;
return (
<DubWidget
token={publicToken}
variant="inline"
options={{ onTokenExpired: () => mutate() }}
/>
);
}
2 changes: 1 addition & 1 deletion packages/embeds/react/src/example/widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const Widget = () => {
createToken();
}, []);

return <DubWidget token={token} onTokenExpired={createToken} />;
return <DubWidget token={token} options={{ onTokenExpired: createToken }} />;
};

ReactDom.render(<Widget />, document.getElementById("root"));

0 comments on commit 5b7f35a

Please sign in to comment.