login page added
This commit is contained in:
parent
c33e446352
commit
daac48c8e8
@ -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/
|
||||
|
@ -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';
|
||||
// <pages
|
||||
|
||||
@ -73,7 +74,7 @@ function App(): React.JSX.Element {
|
||||
|
||||
return (
|
||||
<NavigationContainer>
|
||||
<SearchPage />
|
||||
<LoginPage />
|
||||
</NavigationContainer>
|
||||
);
|
||||
}
|
||||
|
7
dialpods/package-lock.json
generated
7
dialpods/package-lock.json
generated
@ -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",
|
||||
|
@ -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"
|
||||
|
136
dialpods/pages/Login.tsx
Normal file
136
dialpods/pages/Login.tsx
Normal file
@ -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<string> {
|
||||
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 (
|
||||
<View>
|
||||
<Text>Login to your Kinode</Text>
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
placeholder="URL"
|
||||
value={nodeURL}
|
||||
onChangeText={setURL}
|
||||
placeholderTextColor="#666"
|
||||
/>
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
placeholder="password"
|
||||
value={password}
|
||||
secureTextEntry={true}
|
||||
onChangeText={setPassword}
|
||||
placeholderTextColor="#666"
|
||||
/>
|
||||
<Button title="Submit" onPress={submit} />
|
||||
{loading && <ActivityIndicator color="#f97316" />}
|
||||
{error && <Text style={styles.error}>{error}</Text>}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
export default LoginPage;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
backgroundColor: 'white',
|
||||
},
|
||||
navbar: {
|
||||
padding: 16,
|
||||
backgroundColor: 'white',
|
||||
borderBottomWidth: 1,
|
||||
borderBottomColor: '#e5e5e5',
|
||||
},
|
||||
navbarText: {
|
||||
fontSize: 18,
|
||||
fontWeight: '600',
|
||||
},
|
||||
resultContainer: {
|
||||
flex: 1,
|
||||
},
|
||||
searchBar: {
|
||||
flexDirection: 'row',
|
||||
alignItems: 'center',
|
||||
padding: 16,
|
||||
borderTopWidth: 1,
|
||||
borderTopColor: 'black',
|
||||
},
|
||||
input: {
|
||||
flex: 1,
|
||||
height: 40,
|
||||
marginRight: 8,
|
||||
padding: 8,
|
||||
color: 'black',
|
||||
},
|
||||
resultItem: {
|
||||
flexDirection: 'row',
|
||||
alignItems: 'center',
|
||||
padding: 24,
|
||||
backgroundColor: '#d4d4d4',
|
||||
marginBottom: 1,
|
||||
},
|
||||
resultImage: {
|
||||
width: 32,
|
||||
height: 32,
|
||||
marginRight: 16,
|
||||
},
|
||||
resultName: {
|
||||
flex: 1,
|
||||
color: 'black',
|
||||
},
|
||||
saveButton: {
|
||||
backgroundColor: '#f97316',
|
||||
paddingHorizontal: 16,
|
||||
paddingVertical: 8,
|
||||
borderRadius: 4,
|
||||
},
|
||||
saveButtonText: {
|
||||
color: 'white',
|
||||
},
|
||||
error: {
|
||||
color: 'red',
|
||||
},
|
||||
});
|
@ -1,3 +1,3 @@
|
||||
# This file was automatically generated by nix-shell.
|
||||
sdk.dir=/nix/store/51jkq88vczmzhy2h0nnv1basncb0qiqi-androidsdk/libexec/android-sdk
|
||||
ndk.dir=/nix/store/51jkq88vczmzhy2h0nnv1basncb0qiqi-androidsdk/libexec/android-sdk/ndk/
|
||||
sdk.dir=/nix/store/q687sci8s6gkg11kh5xbkbh00jdd3mcp-androidsdk/libexec/android-sdk
|
||||
ndk.dir=/nix/store/q687sci8s6gkg11kh5xbkbh00jdd3mcp-androidsdk/libexec/android-sdk/ndk/
|
||||
|
Loading…
x
Reference in New Issue
Block a user