Files
new-api/web/src/components/sign-out-dialog.tsx
T
Calcium-Ion 31d70fca39 refactor(auth): replace dashboard sessions with stateless tokens and session control (#6329)
* refactor(auth): replace dashboard sessions with stateless tokens

* feat(auth): harden session issuance and distributed enforcement

* fix(proxy): preserve trusted proxy compatibility defaults

* refactor: address dashboard auth review feedback

* refactor: remove classic frontend and flatten web app
2026-07-20 16:48:43 +08:00

76 lines
2.4 KiB
TypeScript

/*
Copyright (C) 2023-2026 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import { useQueryClient } from '@tanstack/react-query'
import { useNavigate } from '@tanstack/react-router'
import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import { toast } from 'sonner'
import { ConfirmDialog } from '@/components/confirm-dialog'
import { logout } from '@/features/auth/api'
import { clearAuthenticatedClientState } from '@/lib/auth-session'
interface SignOutDialogProps {
open: boolean
onOpenChange: (open: boolean) => void
}
export function SignOutDialog({ open, onOpenChange }: SignOutDialogProps) {
const { t } = useTranslation()
const navigate = useNavigate()
const queryClient = useQueryClient()
const [isSigningOut, setIsSigningOut] = useState(false)
const handleSignOut = async () => {
setIsSigningOut(true)
try {
const response = await logout()
if (!response.success) {
toast.error(response.message || t('Failed to sign out session'))
return
}
clearAuthenticatedClientState(queryClient)
toast.success(t('Signed out'))
void navigate({ to: '/sign-in', replace: true })
} catch (error: unknown) {
toast.error(
error instanceof Error ? error.message : t('Failed to sign out session')
)
} finally {
setIsSigningOut(false)
}
}
return (
<ConfirmDialog
open={open}
onOpenChange={onOpenChange}
title={t('Sign out')}
desc={t(
'Are you sure you want to sign out? You will need to sign in again to access your account.'
)}
confirmText={t('Sign out')}
handleConfirm={handleSignOut}
isLoading={isSigningOut}
className='sm:max-w-sm'
/>
)
}