Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev Server SSE Test #31

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion screen/terms/terms.jsx
Original file line number Diff line number Diff line change
@@ -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 (
<View style={styles.container}>
<View style={{}}>
Expand Down
24 changes: 22 additions & 2 deletions test/apple/login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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" });
Expand Down Expand Up @@ -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 (
<View style={styles.container}>
<AppleAuthentication.AppleAuthenticationButton
Expand Down