change
This commit is contained in:
parent
47af1685be
commit
fdc903a3c1
2 changed files with 4 additions and 26 deletions
|
|
@ -11,24 +11,7 @@
|
|||
const params = new URLSearchParams(hash);
|
||||
const accessToken = params.get("access_token");
|
||||
|
||||
if (accessToken) {
|
||||
// 서버로 전송
|
||||
fetch("/token", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ access_token: accessToken })
|
||||
}).then((data) => {
|
||||
document.body.innerHTML = "<h2>✅ Login Success!</h2>";
|
||||
document.body.innerHTML += "<a href='/'>go to home</a>";
|
||||
// 가져온 정보를 사용하여 아래에 정보 표시
|
||||
document.body.innerHTML += "<h3>Access Token: " + accessToken + "</h3>";
|
||||
document.body.innerHTML += "<h3>Email : " + data.email + "</h3>";
|
||||
document.body.innerHTML += "<h3>Name : " + data.name + "</h3>";
|
||||
document.body.innerHTML += "<h3>Profile Picture : " + data.picture + "</h3>";
|
||||
});
|
||||
} else {
|
||||
document.body.innerHTML = "<h2>❌ Error: Access Token does not exist.</h2>";
|
||||
}
|
||||
location.href = "/token?access_token=" + accessToken;
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
11
server.js
11
server.js
|
|
@ -7,8 +7,8 @@ app.use(express.static("public")); // public 폴더 내 정적 파일 제공
|
|||
app.use(express.json()); // JSON 본문 파싱
|
||||
|
||||
// Access Token 수신용 엔드포인트
|
||||
app.post("/token", async (req, res) => {
|
||||
const token = req.body.access_token;
|
||||
app.get("/token", async (req, res) => {
|
||||
const token = req.query.access_token;
|
||||
try {
|
||||
const response = await fetch("https://www.googleapis.com/oauth2/v3/userinfo", {
|
||||
headers: {
|
||||
|
|
@ -23,12 +23,7 @@ app.post("/token", async (req, res) => {
|
|||
res.send({
|
||||
email: userInfo.email,
|
||||
name: userInfo.name,
|
||||
token: token,
|
||||
id: userInfo.id,
|
||||
picture: userInfo.picture,
|
||||
gender: userInfo.gender,
|
||||
birthday: userInfo.birthday,
|
||||
age: userInfo.age
|
||||
token: token
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("❌ Error:", err);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue