Skip to content

Commit 6072a71

Browse files
committed
user purge custom render
1 parent 5f41ceb commit 6072a71

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog for `react-static-web-apps-auth`
22

3+
## [1.7.1] - 2024-03-26
4+
5+
## Added
6+
7+
- Custom render function support for User Purge component
8+
39
## [1.7.0] - 2024-03-26
410

511
### Added

react-static-web-apps-auth/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@aaronpowell/react-static-web-apps-auth",
3-
"version": "1.7.0",
3+
"version": "1.7.1",
44
"description": "A library to help creating authenticated React apps on Azure Static Web Apps",
55
"main": "build/index.js",
66
"types": "build/index.d.ts",

react-static-web-apps-auth/src/UserPurge.tsx

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,50 @@ import React from "react";
22
import { StaticWebAppsClassName } from "./constants";
33
import { AuthProviders } from "./types";
44

5+
type UserPurgeRenderProps = {
6+
label: string;
7+
href: string;
8+
className: string;
9+
};
10+
511
const UserPurge = ({
612
globally,
713
provider,
8-
label
14+
label,
15+
customRenderer,
916
}: {
1017
globally: boolean;
1118
provider: AuthProviders;
12-
label?: string
19+
label?: string;
20+
customRenderer?: (props: UserPurgeRenderProps) => JSX.Element;
1321
}) => {
1422
const host = globally ? "identity.azurestaticapps.net" : location.hostname;
23+
const href = `https://${host}/.auth/purge/${provider}`;
24+
const className = `purge ${StaticWebAppsClassName}`;
1525

16-
return (
17-
<a
18-
href={`https://${host}/.auth/purge/${provider}`}
19-
className={`purge ${StaticWebAppsClassName}`}
20-
>
21-
{label ?? "Purge user information"}
22-
</a>
26+
return customRenderer ? (
27+
customRenderer({
28+
href,
29+
className,
30+
label: label ?? "Purge user information",
31+
})
32+
) : (
33+
<DefaultRenderer
34+
href={href}
35+
className={className}
36+
label={label ?? "Purge user information"}
37+
/>
2338
);
2439
};
2540

2641
UserPurge.defaultProps = {
2742
globally: false,
2843
};
2944

45+
const DefaultRenderer = (props: UserPurgeRenderProps) => (
46+
<a href={props.href} className={props.className}>
47+
{props.label}
48+
</a>
49+
);
50+
3051
export { UserPurge };

0 commit comments

Comments
 (0)