staging #223

Merged
b merged 28 commits from staging into main 2024-10-09 13:50:23 +00:00
2 changed files with 21 additions and 14 deletions
Showing only changes of commit 331759de5c - Show all commits

View File

@ -1,16 +1,15 @@
import { logout as nostrLogout } from 'nostr-login' import { logout as nostrLogout } from 'nostr-login'
import { clear } from '../utils/localStorage' import { clear } from '../utils/localStorage'
import { useDispatch } from 'react-redux'
import { Dispatch } from '../store/store'
import { userLogOutAction } from '../store/actions' import { userLogOutAction } from '../store/actions'
import { LoginMethod } from '../store/auth/types' import { LoginMethod } from '../store/auth/types'
import { useAppSelector } from './store' import { useAppDispatch, useAppSelector } from './store'
import { useCallback } from 'react'
export const useLogout = () => { export const useLogout = () => {
const loginMethod = useAppSelector((state) => state.auth?.loginMethod) const loginMethod = useAppSelector((state) => state.auth?.loginMethod)
const dispatch: Dispatch = useDispatch() const dispatch = useAppDispatch()
const logout = () => { const logout = useCallback(() => {
// Log out of the nostr-login // Log out of the nostr-login
if (loginMethod === LoginMethod.nostrLogin) { if (loginMethod === LoginMethod.nostrLogin) {
nostrLogout() nostrLogout()
@ -21,7 +20,7 @@ export const useLogout = () => {
// Clear the local storage states // Clear the local storage states
clear() clear()
} }, [dispatch, loginMethod])
return logout return logout
} }

View File

@ -74,7 +74,6 @@ export const MainLayout = () => {
useEffect(() => { useEffect(() => {
const handleNostrAuth = (_: string, opts: NostrLoginAuthOptions) => { const handleNostrAuth = (_: string, opts: NostrLoginAuthOptions) => {
console.log(opts.method)
if (opts.type === 'logout') { if (opts.type === 'logout') {
logout() logout()
} else { } else {
@ -83,12 +82,22 @@ export const MainLayout = () => {
} }
} }
initNostrLogin({ ;(async () => {
darkMode: false, try {
noBanner: true, const options = {
onAuth: handleNostrAuth methods: ['connect', 'extension', 'local'],
}) noBanner: true,
onAuth: handleNostrAuth
}
await initNostrLogin(options)
console.log('Nostr-Login initialized successfully')
} catch (error) {
console.error('Failed to initialize Nostr-Login', error)
}
})()
}, [dispatch, login, logout])
useEffect(() => {
const metadataController = MetadataController.getInstance() const metadataController = MetadataController.getInstance()
const restoredState = loadState() const restoredState = loadState()
@ -119,8 +128,7 @@ export const MainLayout = () => {
} else { } else {
setIsLoading(false) setIsLoading(false)
} }
// eslint-disable-next-line react-hooks/exhaustive-deps }, [dispatch, logout])
}, [])
useEffect(() => { useEffect(() => {
if (authState && authState.loggedIn && usersAppData) { if (authState && authState.loggedIn && usersAppData) {