Skip to content

Commit 9990370

Browse files
authored
Merge pull request #21 from omthakare16/main
added SignOutButton Component with callbacks
2 parents 7c59e90 + 2f7699f commit 9990370

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
const logoutLink =
8+
auth.settings.authority.substring(0, auth.settings.authority.lastIndexOf('/')) +
9+
'/logout?target=' +
10+
btoa(callback || window.location.href);
11+
12+
return (
13+
<div
14+
onClick={() => {
15+
auth.removeUser().then(() => (window.location.href = logoutLink));
16+
}}
17+
>
18+
{children ? children : <button style={{cursor: 'pointer'}}>Sign Out</button>}
19+
</div>
20+
);
21+
};
22+
23+
24+
SignOutButton.propTypes = {
25+
callback: PropTypes.string,
26+
children: PropTypes.node,
27+
};

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)