diff --git a/screen/terms/terms.jsx b/screen/terms/terms.jsx index edd07e81..ed5f4d92 100644 --- a/screen/terms/terms.jsx +++ b/screen/terms/terms.jsx @@ -1,12 +1,58 @@ -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 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); + } + }; + + // sse response + // 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(); + }, []); + return ( diff --git a/test/apple/login.jsx b/test/apple/login.jsx index 16b20694..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,8 +77,9 @@ const AppleLogin = () => { await AsyncStorage.setItem("refresh_token", refresh_token); console.log("토큰:::", access_token); - // 사용자 정보 가져오기 + // 사용자 정보 가져오기 및 SSE 연결 await fetchUserProfile(); + // await sseConnect(); if (response.data.data.isUserRegistered) { navigation.replace("MainScreen", { screen: "Spending" }); @@ -135,6 +139,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 (