From 14639c40be4325d3ae28fc7e9b62379e3368df35 Mon Sep 17 00:00:00 2001 From: yeoniii20 Date: Tue, 30 Jul 2024 00:56:10 +0900 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20login=20=EC=9D=B4=ED=9B=84=20sse=20?= =?UTF-8?q?connect?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/apple/login.jsx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/apple/login.jsx b/test/apple/login.jsx index 16b20694..ece41dc2 100644 --- a/test/apple/login.jsx +++ b/test/apple/login.jsx @@ -76,6 +76,8 @@ const AppleLogin = () => { // 사용자 정보 가져오기 await fetchUserProfile(); + // sse 연결하기 + await sseConnect(); if (response.data.data.isUserRegistered) { navigation.replace("MainScreen", { screen: "Spending" }); @@ -135,6 +137,22 @@ const AppleLogin = () => { } }; + // sse connect + const sseConnect = async () => { + const accessToken = await AsyncStorage.getItem("access_token"); + try { + const response = await axios.get(`${url}/api/sse/subscribe`, { + headers: { + Authorization: `Bearer ${accessToken}`, + }, + params: {}, + }); + console.log("sse connect test ::: 연결합니다....", response.data); + } catch (error) { + console.error("sse 에러:", error); + } + }; + return ( Date: Wed, 31 Jul 2024 00:39:43 +0900 Subject: [PATCH 2/5] fix: edit login logic --- test/apple/login.jsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/apple/login.jsx b/test/apple/login.jsx index ece41dc2..9fc96130 100644 --- a/test/apple/login.jsx +++ b/test/apple/login.jsx @@ -23,7 +23,10 @@ const AppleLogin = () => { }); const idTokenVal = credential.identityToken; if (credential.authorizationCode) { - AsyncStorage.setItem("authorizationCode", credential.authorizationCode); + await AsyncStorage.setItem( + "authorizationCode", + credential.authorizationCode + ); console.log("서버로 인증 코드를 전송합니다 :::", idTokenVal); // 서버로 인증 코드 전송 await fetchData(idTokenVal); @@ -74,10 +77,9 @@ const AppleLogin = () => { await AsyncStorage.setItem("refresh_token", refresh_token); console.log("토큰:::", access_token); - // 사용자 정보 가져오기 + // 사용자 정보 가져오기 및 SSE 연결 await fetchUserProfile(); - // sse 연결하기 - await sseConnect(); + // await sseConnect(); if (response.data.data.isUserRegistered) { navigation.replace("MainScreen", { screen: "Spending" }); From 6b5db3c01f27e1da955db3ec7d86f275f9ce48b5 Mon Sep 17 00:00:00 2001 From: yeoniii20 Date: Wed, 31 Jul 2024 00:39:56 +0900 Subject: [PATCH 3/5] feat: sse test --- screen/terms/terms.jsx | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/screen/terms/terms.jsx b/screen/terms/terms.jsx index edd07e81..90c039a3 100644 --- a/screen/terms/terms.jsx +++ b/screen/terms/terms.jsx @@ -1,12 +1,38 @@ -import React from "react"; +import React, { useEffect } from "react"; import { View, Image, Text, TouchableOpacity, ScrollView } from "react-native"; import { styles } from "./terms.styles"; import { useNavigation } from "@react-navigation/native"; import { TermsData } from "../../data/termsData"; +import AsyncStorage from "@react-native-async-storage/async-storage"; +import apiClient from "../../api/apiClient"; const Terms = () => { const navigation = useNavigation(); + // sse connect + const sseConnect = async () => { + console.log("test123"); + const url = "/api/sse/subscribe"; + try { + console.log("test12345"); + + const response = await apiClient.get(url, { + headers: { + "Content-Type": "application/json; charset=utf-8", + }, + // params: {}, + }); + console.log("sse connect test ::: 연결합니다....", response.data); + } catch (error) { + console.error("sse 에러:", error); + } + }; + + useEffect(() => { + console.log("test"); + sseConnect(); + }, []); + return ( From 1e325a17503d7ae30a2b433f4d941ee08cf8b09d Mon Sep 17 00:00:00 2001 From: yeoniii20 Date: Wed, 31 Jul 2024 00:58:37 +0900 Subject: [PATCH 4/5] feat: add response example --- screen/terms/terms.jsx | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/screen/terms/terms.jsx b/screen/terms/terms.jsx index 90c039a3..e88f6c4a 100644 --- a/screen/terms/terms.jsx +++ b/screen/terms/terms.jsx @@ -28,6 +28,26 @@ const Terms = () => { } }; + // event:SSE CONNECTED + // data:"SSE 연결" + + // event:heartbeat + // data:"heartbeat message" + + // event:heartbeat + // data:"heartbeat message" + + // event:heartbeat + // data:"heartbeat message" + + // event:heartbeat + // data:"heartbeat message" + + // event:heartbeat + // data:"heartbeat message" + + // {"status":400} + useEffect(() => { console.log("test"); sseConnect(); From 68d5c4a2d092041867789bc4e60831c675afa7fd Mon Sep 17 00:00:00 2001 From: yeoniii20 Date: Thu, 29 Aug 2024 22:22:42 +0900 Subject: [PATCH 5/5] comment: add sse response example --- screen/terms/terms.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/screen/terms/terms.jsx b/screen/terms/terms.jsx index e88f6c4a..ed5f4d92 100644 --- a/screen/terms/terms.jsx +++ b/screen/terms/terms.jsx @@ -3,7 +3,6 @@ import { View, Image, Text, TouchableOpacity, ScrollView } from "react-native"; import { styles } from "./terms.styles"; import { useNavigation } from "@react-navigation/native"; import { TermsData } from "../../data/termsData"; -import AsyncStorage from "@react-native-async-storage/async-storage"; import apiClient from "../../api/apiClient"; const Terms = () => { @@ -28,6 +27,7 @@ const Terms = () => { } }; + // sse response // event:SSE CONNECTED // data:"SSE 연결"