All checks were successful
Open PR on Staging / audit_and_check (pull_request) Successful in 34s
27 lines
759 B
TypeScript
27 lines
759 B
TypeScript
import { logout as nostrLogout } from 'nostr-login'
|
|
import { clear } from '../utils/localStorage'
|
|
import { userLogOutAction } from '../store/actions'
|
|
import { LoginMethod } from '../store/auth/types'
|
|
import { useAppDispatch, useAppSelector } from './store'
|
|
import { useCallback } from 'react'
|
|
|
|
export const useLogout = () => {
|
|
const loginMethod = useAppSelector((state) => state.auth?.loginMethod)
|
|
const dispatch = useAppDispatch()
|
|
|
|
const logout = useCallback(() => {
|
|
// Log out of the nostr-login
|
|
if (loginMethod === LoginMethod.nostrLogin) {
|
|
nostrLogout()
|
|
}
|
|
|
|
// Reset redux state with the logout
|
|
dispatch(userLogOutAction())
|
|
|
|
// Clear the local storage states
|
|
clear()
|
|
}, [dispatch, loginMethod])
|
|
|
|
return logout
|
|
}
|