Skip to content

Commit 2f7699f

Browse files
committed
changed the Logout redirect logic + refactored the code
1 parent 85eb35c commit 2f7699f

File tree

1 file changed

+11
-33
lines changed

1 file changed

+11
-33
lines changed

src/components/SignOutButton/SignOutButton.jsx

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,19 @@ import React from 'react';
44

55
export const SignOutButton = ({callback, children}) => {
66
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-
}
7+
const logoutLink =
8+
auth.settings.authority.substring(0, auth.settings.authority.lastIndexOf('/')) +
9+
'/logout?target=' +
10+
btoa(callback || window.location.href);
11+
2612
return (
27-
<a
28-
href={
29-
process.env.REACT_APP_EASYAUTH_APP_URL +
30-
'/logout?target=' +
31-
btoa(callback || window.location.href)
32-
}
13+
<div
14+
onClick={() => {
15+
auth.removeUser().then(() => (window.location.href = logoutLink));
16+
}}
3317
>
34-
<div
35-
onClick={() => {
36-
auth.removeUser();
37-
}}
38-
>
39-
{children}
40-
</div>
41-
</a>
18+
{children ? children : <button style={{cursor: 'pointer'}}>Sign Out</button>}
19+
</div>
4220
);
4321
};
4422

0 commit comments

Comments
 (0)