@@ -22,6 +22,7 @@ import SvgSettings from "@/icons/settings";
22
22
import SvgLogOut from "@/icons/log-out" ;
23
23
import SvgBell from "@/icons/bell" ;
24
24
import SvgX from "@/icons/x" ;
25
+ import { useRouter } from "next/navigation" ;
25
26
26
27
function getUsernameFromEmail ( email ?: string ) : string {
27
28
if ( ! email ) return ANONYMOUS_USER_NAME ;
@@ -49,12 +50,26 @@ export default function Settings({ folded }: SettingsProps) {
49
50
error,
50
51
mutate : refreshNotifications ,
51
52
} = useSWR < Notification [ ] > ( "/api/notifications" , errorHandlingFetcher ) ;
53
+ const router = useRouter ( ) ;
52
54
53
55
const showAdminPanel = ! user || user . role === UserRole . ADMIN ;
54
56
const showCuratorPanel = user && isCurator ;
55
57
const showLogout =
56
58
user && ! checkUserIsNoAuthUser ( user . id ) && ! LOGOUT_DISABLED ;
57
59
60
+ async function handleLogout ( ) {
61
+ const isSuccess = await logout ( ) ;
62
+
63
+ if ( ! isSuccess ) {
64
+ alert ( "Failed to logout" ) ;
65
+ return ;
66
+ }
67
+
68
+ router . push (
69
+ `/auth/login?next=${ encodeURIComponent ( window . location . pathname + window . location . search ) } `
70
+ ) ;
71
+ }
72
+
58
73
return (
59
74
< >
60
75
< Popover open = { settingsPopupOpen } onOpenChange = { setSettingsPopupOpen } >
@@ -132,14 +147,14 @@ export default function Settings({ folded }: SettingsProps) {
132
147
{ `Notifications ${ ( notifications && notifications . length ) || 0 > 0 ? `(${ notifications ! . length } )` : "" } ` }
133
148
</ MenuButton >
134
149
135
- { showLogout && (
150
+ { ! showLogout && (
136
151
< >
137
152
{ ( showCuratorPanel ||
138
153
showAdminPanel ||
139
154
dropdownItems . length > 0 ) && (
140
155
< div className = "border-b mx-padding-button" />
141
156
) }
142
- < MenuButton icon = { SvgLogOut } danger >
157
+ < MenuButton icon = { SvgLogOut } danger onClick = { handleLogout } >
143
158
Log out
144
159
</ MenuButton >
145
160
</ >
0 commit comments