21 lines
483 B
TypeScript
21 lines
483 B
TypeScript
|
|
import { useSWRConfig } from 'swr'
|
|||
|
|
import { clearAdminToken, getAdminSessionKey } from 'infra/backend-api'
|
|||
|
|
|
|||
|
|
import type { LogoutAction } from '../types/auth-api.type'
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* Сценарий выхода администратора.
|
|||
|
|
*/
|
|||
|
|
export const useLogout = (): LogoutAction => {
|
|||
|
|
const { mutate } = useSWRConfig()
|
|||
|
|
|
|||
|
|
const logout = async () => {
|
|||
|
|
clearAdminToken()
|
|||
|
|
await mutate(getAdminSessionKey(), undefined, { revalidate: false })
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return {
|
|||
|
|
logout,
|
|||
|
|
}
|
|||
|
|
}
|