Skip to content

Commit 85eb35c

Browse files
committed
added SignOutButton Component with callbacks
1 parent a106b57 commit 85eb35c

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@easyauth.io/easyauth-react",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "React SDK for EasyAuth",
55
"main": "dist/index.js",
66
"module": "dist/index.es.js",
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import {useEasyauth} from '../../hooks/useEasyauth/useEasyauth.jsx';
2+
import PropTypes from 'prop-types';
3+
import React from 'react';
4+
5+
export const SignOutButton = ({callback, children}) => {
6+
const auth = useEasyauth();
7+
if (!children) {
8+
return (
9+
<a
10+
href={
11+
process.env.REACT_APP_EASYAUTH_APP_URL +
12+
'/logout?target=' +
13+
btoa(callback || window.location.href)
14+
}
15+
>
16+
<button
17+
onClick={() => {
18+
auth.removeUser();
19+
}}
20+
>
21+
Sign Out
22+
</button>
23+
</a>
24+
);
25+
}
26+
return (
27+
<a
28+
href={
29+
process.env.REACT_APP_EASYAUTH_APP_URL +
30+
'/logout?target=' +
31+
btoa(callback || window.location.href)
32+
}
33+
>
34+
<div
35+
onClick={() => {
36+
auth.removeUser();
37+
}}
38+
>
39+
{children}
40+
</div>
41+
</a>
42+
);
43+
};
44+
45+
46+
SignOutButton.propTypes = {
47+
callback: PropTypes.string,
48+
children: PropTypes.node,
49+
};

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ export * from './components/SignedInAndSignedOut/SignedOut.jsx';
66
export * from './hooks/useUser/useUser.jsx';
77
export * from './hooks/useStripe/useStripe.jsx';
88
export * from './components/UserButton/UserButton.jsx';
9+
export * from './components/SignOutButton/SignOutButton.jsx';

0 commit comments

Comments
 (0)