From 568211ad42f48e7f0f8df89dad436bb165fab29a Mon Sep 17 00:00:00 2001 From: sudaltokki Date: Tue, 18 Oct 2022 21:32:38 +0900 Subject: [PATCH] 221018_Jiwon_Auto Login --- package-lock.json | 52 +++++++++++++++++++++++++++++++ package.json | 1 + src/components/Input.js | 2 +- src/components/auth/KakaoLogin.js | 4 +++ src/components/auth/NaverLogin.js | 5 +++ src/screens/MainScreen.js | 2 +- src/screens/RootStack.js | 21 +++++++++++-- src/screens/Search.js | 16 ++++------ 8 files changed, 88 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6c10767..9b69f65 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "0.0.1", "dependencies": { "@actbase/react-daum-postcode": "^1.0.4", + "@react-native-async-storage/async-storage": "^1.17.10", "@react-native-community/checkbox": "^0.5.12", "@react-native-community/masked-view": "^0.1.11", "@react-native-seoul/kakao-login": "^4.2.2", @@ -8070,6 +8071,17 @@ "@jridgewell/sourcemap-codec": "^1.4.10" } }, + "node_modules/@react-native-async-storage/async-storage": { + "version": "1.17.10", + "resolved": "https://registry.npmjs.org/@react-native-async-storage/async-storage/-/async-storage-1.17.10.tgz", + "integrity": "sha512-KrR021BmBLsA0TT1AAsfH16bHYy0MSbhdAeBAqpriak3GS1T2alFcdTUvn13p0ZW6FKRD6Bd3ryU2zhU/IYYJQ==", + "dependencies": { + "merge-options": "^3.0.4" + }, + "peerDependencies": { + "react-native": "^0.0.0-0 || 0.60 - 0.70 || 1000.0.0" + } + }, "node_modules/@react-native-community/checkbox": { "version": "0.5.12", "resolved": "https://registry.npmjs.org/@react-native-community/checkbox/-/checkbox-0.5.12.tgz", @@ -13994,6 +14006,14 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-plain-obj": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-2.1.0.tgz", + "integrity": "sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==", + "engines": { + "node": ">=8" + } + }, "node_modules/is-plain-object": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz", @@ -16465,6 +16485,17 @@ "resolved": "https://registry.npmjs.org/memoize-one/-/memoize-one-5.2.1.tgz", "integrity": "sha512-zYiwtZUcYyXKo/np96AGZAckk+FWWsUdJ3cHGGmld7+AhvcWmQyGCYUh1hc4Q/pkOhb65dQR/pqCyK0cOaHz4Q==" }, + "node_modules/merge-options": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/merge-options/-/merge-options-3.0.4.tgz", + "integrity": "sha512-2Sug1+knBjkaMsMgf1ctR1Ujx+Ayku4EdJN4Z+C2+JzoeF7A3OZ9KM2GY0CpQS51NR61LTurMJrRKPhSs3ZRTQ==", + "dependencies": { + "is-plain-obj": "^2.1.0" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/merge-stream": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", @@ -28570,6 +28601,14 @@ "@jridgewell/sourcemap-codec": "^1.4.10" } }, + "@react-native-async-storage/async-storage": { + "version": "1.17.10", + "resolved": "https://registry.npmjs.org/@react-native-async-storage/async-storage/-/async-storage-1.17.10.tgz", + "integrity": "sha512-KrR021BmBLsA0TT1AAsfH16bHYy0MSbhdAeBAqpriak3GS1T2alFcdTUvn13p0ZW6FKRD6Bd3ryU2zhU/IYYJQ==", + "requires": { + "merge-options": "^3.0.4" + } + }, "@react-native-community/checkbox": { "version": "0.5.12", "resolved": "https://registry.npmjs.org/@react-native-community/checkbox/-/checkbox-0.5.12.tgz", @@ -33050,6 +33089,11 @@ "has-tostringtag": "^1.0.0" } }, + "is-plain-obj": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-2.1.0.tgz", + "integrity": "sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==" + }, "is-plain-object": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz", @@ -34917,6 +34961,14 @@ "resolved": "https://registry.npmjs.org/memoize-one/-/memoize-one-5.2.1.tgz", "integrity": "sha512-zYiwtZUcYyXKo/np96AGZAckk+FWWsUdJ3cHGGmld7+AhvcWmQyGCYUh1hc4Q/pkOhb65dQR/pqCyK0cOaHz4Q==" }, + "merge-options": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/merge-options/-/merge-options-3.0.4.tgz", + "integrity": "sha512-2Sug1+knBjkaMsMgf1ctR1Ujx+Ayku4EdJN4Z+C2+JzoeF7A3OZ9KM2GY0CpQS51NR61LTurMJrRKPhSs3ZRTQ==", + "requires": { + "is-plain-obj": "^2.1.0" + } + }, "merge-stream": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", diff --git a/package.json b/package.json index 0b3b4eb..04f90f6 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ }, "dependencies": { "@actbase/react-daum-postcode": "^1.0.4", + "@react-native-async-storage/async-storage": "^1.17.10", "@react-native-community/checkbox": "^0.5.12", "@react-native-community/masked-view": "^0.1.11", "@react-native-seoul/kakao-login": "^4.2.2", diff --git a/src/components/Input.js b/src/components/Input.js index fa40496..40757ec 100644 --- a/src/components/Input.js +++ b/src/components/Input.js @@ -87,7 +87,7 @@ const InputType2 = (props) => { const {name, obj} = props; const imageUrl = '../assets/images/' + obj.type + '.png' return( - onChangeType(name, obj.type)}> + onChangeType(name, obj.label)}> {obj.label} diff --git a/src/components/auth/KakaoLogin.js b/src/components/auth/KakaoLogin.js index 6c8f3e8..67c4b56 100644 --- a/src/components/auth/KakaoLogin.js +++ b/src/components/auth/KakaoLogin.js @@ -10,6 +10,7 @@ import { } from "@react-native-seoul/kakao-login"; import { fontPercentage, heightPercentage, widthPercentage } from "../../ResponsiveSize"; import { useNavigation } from "@react-navigation/native"; +import AsyncStorage from '@react-native-async-storage/async-storage'; import { userID } from "../../recoil/recoil"; import { useRecoilState } from "recoil"; @@ -53,6 +54,9 @@ const KakaoLogin = () => { console.log('existBool is false') } else { + AsyncStorage.setItem( + 'userData',JSON.stringify({'id': profile.id, 'token': JSON.stringify(token)}) + ); navigation.navigate('MainScreen'); console.log('existBool is true'); } diff --git a/src/components/auth/NaverLogin.js b/src/components/auth/NaverLogin.js index 5d0d144..65955c6 100644 --- a/src/components/auth/NaverLogin.js +++ b/src/components/auth/NaverLogin.js @@ -2,6 +2,7 @@ import React, {useEffect, useState} from "react"; import { Text,StyleSheet, ScrollView, SafeAreaView,View, Pressable, Button, TouchableOpacity,Image} from "react-native"; import { NaverLogin, getProfile } from "@react-native-seoul/naver-login"; import { heightPercentage, widthPercentage } from "../../ResponsiveSize"; +import AsyncStorage from '@react-native-async-storage/async-storage'; import { useRecoilState } from "recoil"; import { userID } from "../../recoil/recoil"; @@ -41,11 +42,15 @@ const Naver_Login = ({navigation}) => { }).then(response=>response.json()).then(res=> { console.log(res) setUserId(res); + if(res == 0){ navigation.navigate('Nickname',{token:profileResult.response.id}); console.log('existBool is false') } else { + AsyncStorage.setItem( + 'userData',JSON.stringify({'id': profileResult.response.id, 'token': naverToken}) + ); navigation.navigate('MainScreen'); console.log('existBool is true'); } diff --git a/src/screens/MainScreen.js b/src/screens/MainScreen.js index fa8e5a6..aa851bd 100644 --- a/src/screens/MainScreen.js +++ b/src/screens/MainScreen.js @@ -94,6 +94,7 @@ const MyPageStackScreen = ({navigation}) => { const MainScreen = (props) => { const hide = props.routeName == "WriteNanum" || props.routeName == "WriteNanum2" + console.log(hide) return ( { : ), - tabBarStyle: { display: hide ? "none" : "flex" } }} /> { + return ( { }; const RootStack = () => { - return ( + + const [isLoggedIn, setIsLoggedIn] = useState("Loading"); + + useEffect(()=>{ + AsyncStorage.getItem('userData', (err, result) => { + if(JSON.parse(result).id) setIsLoggedIn(true); + else setIsLoggedIn(false); + + console.log(JSON.parse(result)) + });; + console.log(isLoggedIn) + },[]) + + return (isLoggedIn != "Loading" && - + { const path="http://chevita-env.eba-i8jmx3zw.ap-northeast-2.elasticbeanstalk.com/posts"; - const onPressSearch = async() => { - console.log(value) - await fetch(path).then((res)=>res.json()).then((response)=> + useEffect(()=>{ + fetch(path).then((res)=>res.json()).then((response)=> setData(response.data) ) - - let item = [...data]; + },[]) - await setArr(item.filter((item) => item?.title?.includes(value) || item?.content?.includes(value))) + const onPressSearch = () => { + setArr([...data].filter((item) => item?.title?.includes(value) || item?.content?.includes(value))) console.log(arr) - } - - return( - {arr.map(item=>( + {arr.reverse().map(item=>( ))}