import React, { useState, useRef, useEffect } from 'react'; import { View, StyleSheet, Text, Keyboard, Alert, TouchableOpacity, Image, TouchableWithoutFeedback, } from 'react-native'; import Button from '../components/Button'; import TextInput, { IconNames, ReturnKeyTypes } from '../components/TextInput'; import PropTypes from 'prop-types'; import {url} from '../url'; const SignInScreen = ({ navigation }) => { const [id, setId] = useState(''); const [password, setPassword] = useState(''); const passwordRef = useRef(null); const [disabled, setDisabled] = useState(true); const [isLoading, setIsLoading] = useState(false); useEffect(() => { setDisabled(!id || !password); }, [id, password]); const handleDismissKeyboard = () => { Keyboard.dismiss(); }; const onSubmit = async () => { if (!disabled && !isLoading) { Keyboard.dismiss(); setIsLoading(true); try { fetch(`${url}/login`, { method: 'POST', body: JSON.stringify({ id: email, password: password, }), headers: { 'Content-Type': 'application/json', }, }) .then((response) => response.json()) .then(async (data) => { //const token = data.token; // 토큰 추출 //console.log(token); try { //await SecureStore.setItemAsync('Token', token); // 로그인 성공 후 메인 화면으로 이동 navigation.navigate('Main'); } catch (e) { Alert.alert('로그인 실패'); console.error('token 에러: ' + e); setIsLoading(false); } }) .catch((error) => { console.error('tokne 만료:' + error); setIsLoading(false); }); } catch (e) { Alert.alert('로그인 실패', e, [ { text: 'Ok', onPress: () => setIsLoading(false), }, ]); } } }; return ( 스마트 전자서명 시스템 setId(text.trim())} title={'아이디'} returnKeyType={ReturnKeyTypes.NEXT} iconName={IconNames.ID} onSubmitEditing={() => passwordRef.current.focus()} /> setPassword(text.trim())} title={'비밀번호'} secureTextEntry iconName={IconNames.PASSWORD} onSubmitEditing={onSubmit} />