diff --git a/devenv.nix b/devenv.nix index a8b4d6b..92fff7d 100644 --- a/devenv.nix +++ b/devenv.nix @@ -9,13 +9,13 @@ env.GREET = "devenv"; # https://devenv.sh/packages/ - packages = [pkgs.git]; + packages = with pkgs; [git nodePackages.typescript-language-server]; android = { enable = true; - platforms.version = ["35"]; + platforms.version = ["34" "35"]; reactNative.enable = true; - buildTools.version = ["35.0.0"]; + buildTools.version = ["34.0.0" "35.0.0"]; }; # https://devenv.sh/languages/ diff --git a/dialpods/App.tsx b/dialpods/App.tsx index 1df26c6..45db8cc 100644 --- a/dialpods/App.tsx +++ b/dialpods/App.tsx @@ -31,6 +31,7 @@ import Fa6 from 'react-native-vector-icons/FontAwesome6'; import {NavigationContainer} from '@react-navigation/native'; // pages +import LoginPage from './pages/Login.tsx'; import SearchPage from './pages/Search.tsx'; // - + ); } diff --git a/dialpods/package-lock.json b/dialpods/package-lock.json index 205f890..fa81ef6 100644 --- a/dialpods/package-lock.json +++ b/dialpods/package-lock.json @@ -17,6 +17,7 @@ "react-native-html-parser": "^0.1.0", "react-native-safe-area-context": "^5.0.0", "react-native-screens": "^4.3.0", + "react-native-sha256": "^1.4.10", "react-native-url-polyfill": "^2.0.0", "react-native-vector-icons": "^10.2.0", "zustand": "^5.0.2" @@ -11006,6 +11007,12 @@ "react-native": "*" } }, + "node_modules/react-native-sha256": { + "version": "1.4.10", + "resolved": "https://registry.npmjs.org/react-native-sha256/-/react-native-sha256-1.4.10.tgz", + "integrity": "sha512-x12owcA1jQZ1GMUX2xg2+4IOVJciZChcyNvolt6IjLdAFtu1tttDF9aHsCTW1J1SbLGSoYCo/UTAoNZay/YAsg==", + "license": "MIT" + }, "node_modules/react-native-url-polyfill": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/react-native-url-polyfill/-/react-native-url-polyfill-2.0.0.tgz", diff --git a/dialpods/package.json b/dialpods/package.json index b24da91..fa00259 100644 --- a/dialpods/package.json +++ b/dialpods/package.json @@ -19,6 +19,7 @@ "react-native-html-parser": "^0.1.0", "react-native-safe-area-context": "^5.0.0", "react-native-screens": "^4.3.0", + "react-native-sha256": "^1.4.10", "react-native-url-polyfill": "^2.0.0", "react-native-vector-icons": "^10.2.0", "zustand": "^5.0.2" diff --git a/dialpods/pages/Login.tsx b/dialpods/pages/Login.tsx new file mode 100644 index 0000000..eb250e2 --- /dev/null +++ b/dialpods/pages/Login.tsx @@ -0,0 +1,136 @@ +import {sha256} from 'react-native-sha256'; +import React, {useEffect, useState} from 'react'; +import {AsyncRes} from '../logic/types/types'; +import { + View, + Text, + TextInput, + Image, + TouchableOpacity, + StyleSheet, + ActivityIndicator, + ScrollView, + Button, +} from 'react-native'; +async function doHash(s: string) { + return sha256(s); +} +export async function kinodeLogin(url: string, pw: string): AsyncRes { + const hash = await doHash(pw); + const opts = { + method: 'POST', + headers: { + 'content-type': 'application/json', + }, + body: JSON.stringify({password_hash: `0x${hash}`, subdomain: ''}), + }; + const res = await fetch(url + '/login', opts); + console.log(res, 'res'); + const cookie = res.headers.get('set-cookie'); + // res.text() returns the keyfile + if (!cookie) return {error: 'Kinode login failed'}; + return {ok: cookie}; +} + +function LoginPage() { + const [nodeURL, setURL] = useState('https://kino.yago.one'); + const [password, setPassword] = useState(''); + const [loading, setLoading] = useState(false); + const [error, setError] = useState(''); + async function submit() { + setLoading(true); + setError(''); + const res = await kinodeLogin(nodeURL, password); + setLoading(false); + console.log('kinode cookie', res); + if ('ok' in res) setError('ok!'); + else setError('error!'); + } + return ( + + Login to your Kinode + + +