import { ExternalLink, User } from '@tamagui/lucide-icons' import React, {useState} from 'react' import {Button, Anchor,H1, H6, Input, Paragraph, XStack, YStack } from 'tamagui' import { ToastControl } from 'app/CurrentToast' import {useAuth, register} from "./../contexts/authcontext" import { useRouter } from 'expo-router' import {showToast} from "./../components/toastwrapper" import { base64ToBigInt, bigIntToBase64, generatePrivateKey, calculatePublicKey, computeSharedSecret, generateNonce, chacha20Encrypt, chacha20Decrypt } from "./../components/crypto"; import {initializeDatabase, addClient,getClient, closeDatabase} from "./../components/dbconnector" export default function Register() { const [username, setUsername] = useState("") const [password, setpassword] = useState("") const [email, setemail] = useState("") const [err, seterr] = useState("") const [showpassword, setshowpassword] = useState(false) const router = useRouter() const {isloggedin } = useAuth() const handleLogin = async () => { seterr(''); console.log(email, username, password); const clientPrivKey = generatePrivateKey(); const clientPubKey = calculatePublicKey(clientPrivKey); try { const loginSuccess = await register(email, username, password, bigIntToBase64(clientPubKey)); if (loginSuccess) { let storedPrivateKeys =JSON.parse(localStorage.getItem("Keys")) || [] const existingUser = storedPrivateKeys.find(user => user.username === username); if (existingUser) { console.error("User already exists"); return; } const private64 = bigIntToBase64(clientPrivKey) const public64 = bigIntToBase64(clientPubKey) storedPrivateKeys.push({username,private64,public64}) localStorage.setItem("privateKeys", JSON.stringify(storedPrivateKeys)) // Initialize the database and add the client //await initializeDatabase(); //await addClient(username, clientPubKey, clientPrivKey); //closeDatabase(); showToast("success", "successfully registered", "go to the login page and login") setTimeout(() => { router.replace("/login") }, 3000) }else { setUsername("") setpassword("") setemail("") } } catch (err) { console.error(err); seterr('An error occurred while logging in'); } }; return (

Register

Username
Email
Password Forgot password? Add tamagui.config.ts to root and follow the Configuration guide to configure your themes and tokens.
) }