Skip to content

Commit

Permalink
[Fix] 소셜 로그인 기능 불필요한 코드 삭제 및 웨더바 현재 날씨 표시 변경 #34, #10
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeiis committed Nov 24, 2023
1 parent f9cf0ea commit 7c5ce95
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 71 deletions.
24 changes: 0 additions & 24 deletions src/app/api/auth/[...nextauth]/route.ts

This file was deleted.

12 changes: 12 additions & 0 deletions src/app/detail/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"use client";

import WeatherBar from "@/component/WeatherBar";

export default function Detail(): JSX.Element {
return (
<>
<></>
<WeatherBar />
</>
);
}
3 changes: 0 additions & 3 deletions src/app/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ import axios from "axios";
export default function Login() {
const [email, setEmail] = useState<string>("");
const [pw, setPw] = useState<string>("");
const GOOGLE_CLIENT_ID = process.env.GOOGLE_CLIENT_ID;
const GOOGLE_REDIRECT_URI = process.env.GOOGLE_REDIRECT_URI;
const router = useRouter();

useEffect(() => {
// 페이지 로드 시 URL에서 access_token 파싱
Expand Down
87 changes: 43 additions & 44 deletions src/component/WeatherBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ import React from "react";
// }[];
// }


const WeatherBar:React.FC = () => {
const WeatherBar: React.FC = () => {
const API_KEY = "fa3eba61f243af3e8e69086462763172";
const kakao_API_KEY = "3a6c3035c801405eaa71ebb9dc7f474b";
let temp: string | undefined;
const [usetemp, setTemp] = useState<string | undefined>();

const [max, setMax] = useState<string | undefined>();
const [min, setMin] = useState<string | undefined>();
const [weat, setWeat] = useState<string | undefined>();
Expand All @@ -37,51 +36,51 @@ const WeatherBar:React.FC = () => {
useEffect(() => {
// 위치 정보를 비동기적으로 가져오는 함수
const getLocation = async () => {
try {
const position = await new Promise<GeolocationPosition>(
(resolve, reject) => {
navigator.geolocation.getCurrentPosition(resolve, reject);
}
);
try {
const position = await new Promise<GeolocationPosition>(
(resolve, reject) => {
navigator.geolocation.getCurrentPosition(resolve, reject);
},
);

const latitude = position.coords.latitude;
const longitude = position.coords.longitude;
const latitude = position.coords.latitude;
const longitude = position.coords.longitude;

const weatherResponse = await fetch(
`https://api.openweathermap.org/data/2.5/weather?lat=${latitude}&lon=${longitude}&appid=${API_KEY}&units=metric`
);
const weatherData = await weatherResponse.json();
temp = weatherData.main.temp.toFixed(1);
setTemp(temp);
// max = weatherData.main.temp_max.toFixed(1);
setMax(weatherData.main.temp_max.toFixed(1));
setMin(weatherData.main.temp_min.toFixed(1));
setWeat(weatherData.weather[0].main);
// console.log(`온도 : ${temp} ,최고온도 ${max},최저온도 ${min}, 날씨 : ${weat}`);
const weatherResponse = await fetch(
`https://api.openweathermap.org/data/2.5/weather?lat=${latitude}&lon=${longitude}&appid=${API_KEY}&units=metric`,
);
const weatherData = await weatherResponse.json();
temp = weatherData.main.temp.toFixed(1);
setTemp(temp + "℃");
// max = weatherData.main.temp_max.toFixed(1);
setMax(weatherData.main.temp_max.toFixed(1));
setMin(weatherData.main.temp_min.toFixed(1));
setWeat(weatherData.weather[0].main);
// console.log(`온도 : ${temp} ,최고온도 ${max},최저온도 ${min}, 날씨 : ${weat}`);

const addressResponse = await fetch(
`https://dapi.kakao.com/v2/local/geo/coord2address.json?x=${longitude}&y=${latitude}`,
{
method: "GET",
headers: { Authorization: `KakaoAK ${kakao_API_KEY}` },
}
);
const addressData = await addressResponse.json();
setAddress(
addressData.documents[0].address.region_1depth_name +
const addressResponse = await fetch(
`https://dapi.kakao.com/v2/local/geo/coord2address.json?x=${longitude}&y=${latitude}`,
{
method: "GET",
headers: { Authorization: `KakaoAK ${kakao_API_KEY}` },
},
);
const addressData = await addressResponse.json();
setAddress(
addressData.documents[0].address.region_1depth_name +
" " +
addressData.documents[0].address.region_2depth_name
);
addressData.documents[0].address.region_2depth_name,
);

console.log(address);
} catch (error) {
console.error("Error getting location:", error);
}
};

console.log(address);
} catch (error) {
console.error("Error getting location:", error);
}
};
getLocation(); // getLocation 함수 실행
}, []);

getLocation(); // getLocation 함수 실행
}, []);

return (
<div id="container">
<div id="weather">
Expand All @@ -93,7 +92,7 @@ const WeatherBar:React.FC = () => {
height={24}
priority
/>
<span> {usetemp}</span>
<span> {usetemp}</span>
</div>
<div id="maxmin">
<span>최고 {max}℃&nbsp;</span>
Expand All @@ -102,6 +101,6 @@ const WeatherBar:React.FC = () => {
</div>
</div>
);
}
};

export default WeatherBar;

0 comments on commit 7c5ce95

Please sign in to comment.