mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-06-06 18:31:00 +00:00
add back toasts
This commit is contained in:
parent
9a86c71754
commit
16513c71ec
@ -5,16 +5,17 @@ import axios from 'axios';
|
|||||||
import { setPubkey, setUsername } from "@/redux/reducers/userReducer";
|
import { setPubkey, setUsername } from "@/redux/reducers/userReducer";
|
||||||
import { generateSecretKey, getPublicKey } from 'nostr-tools';
|
import { generateSecretKey, getPublicKey } from 'nostr-tools';
|
||||||
import { findKind0Username } from "@/utils/nostr";
|
import { findKind0Username } from "@/utils/nostr";
|
||||||
|
import { useToast } from './useToast';
|
||||||
|
|
||||||
export const useLogin = () => {
|
export const useLogin = () => {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const { showToast } = useToast();
|
||||||
|
|
||||||
// Handle Auto Login
|
// Attempt Auto Login on render
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const autoLogin = async () => {
|
const autoLogin = async () => {
|
||||||
const publicKey = window.localStorage.getItem('pubkey');
|
const publicKey = window.localStorage.getItem('pubkey');
|
||||||
console.log('Auto logging in with public key:', publicKey);
|
|
||||||
|
|
||||||
if (!publicKey) return;
|
if (!publicKey) return;
|
||||||
|
|
||||||
@ -35,10 +36,9 @@ export const useLogin = () => {
|
|||||||
autoLogin();
|
autoLogin();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// Handle Nostr Login
|
|
||||||
const nostrLogin = useCallback(async () => {
|
const nostrLogin = useCallback(async () => {
|
||||||
if (!window || !window.nostr) {
|
if (!window || !window.nostr) {
|
||||||
alert('Nostr is not available');
|
showToast('error', 'Nostr Unavailable', 'Nostr is not available');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,16 +70,17 @@ export const useLogin = () => {
|
|||||||
if (username) dispatch(setUsername(username));
|
if (username) dispatch(setUsername(username));
|
||||||
router.push('/');
|
router.push('/');
|
||||||
} else {
|
} else {
|
||||||
alert('User not created');
|
console.error('Error creating user:', createUserResponse);
|
||||||
}
|
}
|
||||||
} catch (createError) {
|
} catch (createError) {
|
||||||
console.error('Error creating user:', createError);
|
console.error('Error creating user:', createError);
|
||||||
|
showToast('error', 'Error Creating User', 'Failed to create user');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [dispatch, router]);
|
}, [dispatch, router, showToast]);
|
||||||
|
|
||||||
// Handle Anonymous Login
|
|
||||||
const anonymousLogin = useCallback(() => {
|
const anonymousLogin = useCallback(() => {
|
||||||
|
try {
|
||||||
const secretKey = generateSecretKey();
|
const secretKey = generateSecretKey();
|
||||||
const publicKey = getPublicKey(secretKey);
|
const publicKey = getPublicKey(secretKey);
|
||||||
|
|
||||||
@ -87,7 +88,11 @@ export const useLogin = () => {
|
|||||||
window.localStorage.setItem('pubkey', publicKey);
|
window.localStorage.setItem('pubkey', publicKey);
|
||||||
window.localStorage.setItem('seckey', secretKey);
|
window.localStorage.setItem('seckey', secretKey);
|
||||||
router.push('/');
|
router.push('/');
|
||||||
}, [dispatch, router]);
|
} catch (error) {
|
||||||
|
console.error('Error during anonymous login:', error);
|
||||||
|
showToast('error', 'Error Logging In', 'Failed to log in');
|
||||||
|
}
|
||||||
|
}, [dispatch, router, showToast]);
|
||||||
|
|
||||||
return { nostrLogin, anonymousLogin };
|
return { nostrLogin, anonymousLogin };
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user