11'use client' ;
22
3- import React , { useEffect , useState } from 'react' ;
3+ import { Session } from 'next-auth' ;
4+ import { signIn , signOut , useSession } from 'next-auth/react' ;
45import Image from 'next/image' ;
56import Link from 'next/link' ;
67import { usePathname , useRouter } from 'next/navigation' ;
7- import { Session } from 'next-auth' ;
8- import { signIn , signOut , useSession } from 'next-auth/react' ;
98import {
10- Avatar ,
11- Button ,
12- Dialog ,
13- Divider ,
14- IconButton ,
15- Popover ,
16- SearchInput ,
17- Spinner ,
18- Text ,
9+ Avatar ,
10+ Button ,
11+ Dialog ,
12+ Divider ,
13+ IconButton ,
14+ Popover ,
15+ SearchInput ,
16+ Spinner ,
17+ Text ,
1918} from 'opub-ui' ;
19+ import React , { useEffect , useState } from 'react' ;
2020
21+ import { Icons } from '@/components/icons' ;
2122import { useDashboardStore } from '@/config/store' ;
2223import { GraphQL } from '@/lib/api' ;
23- import { Icons } from '@/components/icons' ;
2424import { UserDetailsQryDoc } from '../[entityType]/[entitySlug]/schema' ;
2525import { allOrganizationsListingDoc } from '../[entityType]/schema' ;
2626import Sidebar from './sidebar' ;
@@ -38,20 +38,9 @@ export function MainNav({ hideSearch = false }) {
3838 const [ isOpen , setIsOpen ] = useState ( false ) ;
3939 const [ isExploreOpen , setIsExploreOpen ] = useState ( false ) ;
4040
41- const [ isLoggingOut , setIsLoggingOut ] = React . useState ( false ) ;
4241 const { data : session , status } = useSession ( ) ;
4342 const { setUserDetails, setAllEntityDetails } = useDashboardStore ( ) ;
4443
45- async function keycloakSessionLogOut ( ) {
46- try {
47- setIsLoggingOut ( true ) ;
48- await fetch ( `/api/auth/logout` , { method : 'GET' } ) ;
49- } catch ( err ) {
50- setIsLoggingOut ( false ) ;
51- console . error ( err ) ;
52- }
53- }
54-
5544 const handleSignIn = async ( ) => {
5645 try {
5746 // First attempt sign in
@@ -91,10 +80,6 @@ export function MainNav({ hideSearch = false }) {
9180 fetchData ( ) ;
9281 } , [ session , hasFetched , setUserDetails , setAllEntityDetails ] ) ;
9382
94- if ( isLoggingOut ) {
95- return < LogginOutPage /> ;
96- }
97-
9883 const exploreLinks = [
9984 {
10085 title : 'Datasets' ,
@@ -145,7 +130,6 @@ export function MainNav({ hideSearch = false }) {
145130 data = { [ ...exploreLinks , ...Navigation ] }
146131 session = { session }
147132 status = { status }
148- keycloakSessionLogOut = { keycloakSessionLogOut }
149133 signIn = { signIn }
150134 />
151135 </ div >
@@ -279,7 +263,6 @@ export function MainNav({ hideSearch = false }) {
279263 { session ?. user ? (
280264 < ProfileContent
281265 session = { session }
282- keycloakSessionLogOut = { keycloakSessionLogOut }
283266 />
284267 ) : (
285268 < Button
@@ -302,10 +285,8 @@ export function MainNav({ hideSearch = false }) {
302285
303286export const ProfileContent = ( {
304287 session,
305- keycloakSessionLogOut,
306288} : {
307289 session : Session ;
308- keycloakSessionLogOut : ( ) => Promise < void > ;
309290} ) => {
310291 const [ open , setOpen ] = React . useState ( false ) ;
311292
@@ -362,11 +343,16 @@ export const ProfileContent = ({
362343 < Divider className = "mx-3 my-3 w-auto" />
363344 < div className = "px-3" >
364345 < Button
365- onClick = { ( ) => {
346+ onClick = { async ( ) => {
366347 setOpen ( false ) ;
367- keycloakSessionLogOut ( ) . then ( ( ) =>
368- signOut ( { callbackUrl : '/' } )
369- ) ;
348+ const response = await fetch ( `/api/auth/logout` , { method : 'GET' } ) ;
349+ const data = await response . json ( ) ;
350+
351+ await signOut ( { redirect : false } ) ;
352+
353+ if ( data . url ) {
354+ window . location . href = data . url ;
355+ }
370356 } }
371357 kind = "secondary"
372358 size = "slim"
@@ -381,11 +367,3 @@ export const ProfileContent = ({
381367 ) ;
382368} ;
383369
384- const LogginOutPage = ( ) => {
385- return (
386- < div className = " flex items-center justify-end gap-4 bg-surfaceDefault p-5 lg:p-7" >
387- < Spinner color = "surface" />
388- < Text variant = "headingLg" > Logging out...</ Text >
389- </ div >
390- ) ;
391- } ;
0 commit comments