Skip to content
Snippets Groups Projects
Commit 72b892cf authored by Gwangbin's avatar Gwangbin
Browse files

Add DB Connect

parent a6a36770
No related branches found
No related tags found
No related merge requests found
...@@ -18,6 +18,9 @@ lerna-debug.log* ...@@ -18,6 +18,9 @@ lerna-debug.log*
/coverage /coverage
/.nyc_output /.nyc_output
# production
/build
# IDEs and editors # IDEs and editors
/.idea /.idea
.project .project
......
...@@ -13,12 +13,21 @@ ...@@ -13,12 +13,21 @@
"cors": "^2.8.5", "cors": "^2.8.5",
"dotenv": "^16.3.1", "dotenv": "^16.3.1",
"express": "^4.18.2", "express": "^4.18.2",
"mongoose": "^8.0.1",
"nodemon": "^3.0.1" "nodemon": "^3.0.1"
}, },
"devDependencies": { "devDependencies": {
"@types/express": "^4.17.21" "@types/express": "^4.17.21"
} }
}, },
"node_modules/@mongodb-js/saslprep": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.1.1.tgz",
"integrity": "sha512-t7c5K033joZZMspnHg/gWPE4kandgc2OxE74aYOtGKfgB9VPuVJPix0H6fhmm2erj5PBJ21mqcx34lpIGtUCsQ==",
"dependencies": {
"sparse-bitfield": "^3.0.3"
}
},
"node_modules/@types/body-parser": { "node_modules/@types/body-parser": {
"version": "1.19.5", "version": "1.19.5",
"resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.5.tgz", "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.5.tgz",
...@@ -78,7 +87,6 @@ ...@@ -78,7 +87,6 @@
"version": "20.9.0", "version": "20.9.0",
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.9.0.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.9.0.tgz",
"integrity": "sha512-nekiGu2NDb1BcVofVcEKMIwzlx4NjHlcjhoxxKBNLtz15Y1z7MYf549DFvkHSId02Ax6kGwWntIBPC3l/JZcmw==", "integrity": "sha512-nekiGu2NDb1BcVofVcEKMIwzlx4NjHlcjhoxxKBNLtz15Y1z7MYf549DFvkHSId02Ax6kGwWntIBPC3l/JZcmw==",
"dev": true,
"dependencies": { "dependencies": {
"undici-types": "~5.26.4" "undici-types": "~5.26.4"
} }
...@@ -116,6 +124,20 @@ ...@@ -116,6 +124,20 @@
"@types/node": "*" "@types/node": "*"
} }
}, },
"node_modules/@types/webidl-conversions": {
"version": "7.0.3",
"resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz",
"integrity": "sha512-CiJJvcRtIgzadHCYXw7dqEnMNRjhGZlYK05Mj9OyktqV8uVT8fD2BFOB7S1uwBE3Kj2Z+4UyPmFw/Ixgw/LAlA=="
},
"node_modules/@types/whatwg-url": {
"version": "8.2.2",
"resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-8.2.2.tgz",
"integrity": "sha512-FtQu10RWgn3D9U4aazdwIE2yzphmTJREDqNdODHrbrZmmMqI0vMheC/6NE/J1Yveaj8H+ela+YwWTjq5PGmuhA==",
"dependencies": {
"@types/node": "*",
"@types/webidl-conversions": "*"
}
},
"node_modules/abbrev": { "node_modules/abbrev": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
...@@ -221,6 +243,14 @@ ...@@ -221,6 +243,14 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/bson": {
"version": "6.2.0",
"resolved": "https://registry.npmjs.org/bson/-/bson-6.2.0.tgz",
"integrity": "sha512-ID1cI+7bazPDyL9wYy9GaQ8gEEohWvcUl/Yf0dIdutJxnmInEEyCsb4awy/OiBfall7zBA179Pahi3vCdFze3Q==",
"engines": {
"node": ">=16.20.1"
}
},
"node_modules/bytes": { "node_modules/bytes": {
"version": "3.1.2", "version": "3.1.2",
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz",
...@@ -719,6 +749,14 @@ ...@@ -719,6 +749,14 @@
"node": ">=0.12.0" "node": ">=0.12.0"
} }
}, },
"node_modules/kareem": {
"version": "2.5.1",
"resolved": "https://registry.npmjs.org/kareem/-/kareem-2.5.1.tgz",
"integrity": "sha512-7jFxRVm+jD+rkq3kY0iZDJfsO2/t4BBPeEb2qKn2lR/9KhuksYk5hxzfRYWMPV8P/x2d0kHD306YyWLzjjH+uA==",
"engines": {
"node": ">=12.0.0"
}
},
"node_modules/lru-cache": { "node_modules/lru-cache": {
"version": "6.0.0", "version": "6.0.0",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
...@@ -738,6 +776,11 @@ ...@@ -738,6 +776,11 @@
"node": ">= 0.6" "node": ">= 0.6"
} }
}, },
"node_modules/memory-pager": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz",
"integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg=="
},
"node_modules/merge-descriptors": { "node_modules/merge-descriptors": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz",
...@@ -792,6 +835,126 @@ ...@@ -792,6 +835,126 @@
"node": "*" "node": "*"
} }
}, },
"node_modules/mongodb": {
"version": "6.2.0",
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-6.2.0.tgz",
"integrity": "sha512-d7OSuGjGWDZ5usZPqfvb36laQ9CPhnWkAGHT61x5P95p/8nMVeH8asloMwW6GcYFeB0Vj4CB/1wOTDG2RA9BFA==",
"dependencies": {
"@mongodb-js/saslprep": "^1.1.0",
"bson": "^6.2.0",
"mongodb-connection-string-url": "^2.6.0"
},
"engines": {
"node": ">=16.20.1"
},
"peerDependencies": {
"@aws-sdk/credential-providers": "^3.188.0",
"@mongodb-js/zstd": "^1.1.0",
"gcp-metadata": "^5.2.0",
"kerberos": "^2.0.1",
"mongodb-client-encryption": ">=6.0.0 <7",
"snappy": "^7.2.2",
"socks": "^2.7.1"
},
"peerDependenciesMeta": {
"@aws-sdk/credential-providers": {
"optional": true
},
"@mongodb-js/zstd": {
"optional": true
},
"gcp-metadata": {
"optional": true
},
"kerberos": {
"optional": true
},
"mongodb-client-encryption": {
"optional": true
},
"snappy": {
"optional": true
},
"socks": {
"optional": true
}
}
},
"node_modules/mongodb-connection-string-url": {
"version": "2.6.0",
"resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-2.6.0.tgz",
"integrity": "sha512-WvTZlI9ab0QYtTYnuMLgobULWhokRjtC7db9LtcVfJ+Hsnyr5eo6ZtNAt3Ly24XZScGMelOcGtm7lSn0332tPQ==",
"dependencies": {
"@types/whatwg-url": "^8.2.1",
"whatwg-url": "^11.0.0"
}
},
"node_modules/mongoose": {
"version": "8.0.1",
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-8.0.1.tgz",
"integrity": "sha512-O3TJrtLCt4H1eGf2HoHGcnOcCTWloQkpmIP3hA9olybX3OX2KUjdIIq135HD5paGjZEDJYKn9fw4eH5N477zqQ==",
"dependencies": {
"bson": "^6.2.0",
"kareem": "2.5.1",
"mongodb": "6.2.0",
"mpath": "0.9.0",
"mquery": "5.0.0",
"ms": "2.1.3",
"sift": "16.0.1"
},
"engines": {
"node": ">=16.20.1"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/mongoose"
}
},
"node_modules/mongoose/node_modules/ms": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="
},
"node_modules/mpath": {
"version": "0.9.0",
"resolved": "https://registry.npmjs.org/mpath/-/mpath-0.9.0.tgz",
"integrity": "sha512-ikJRQTk8hw5DEoFVxHG1Gn9T/xcjtdnOKIU1JTmGjZZlg9LST2mBLmcX3/ICIbgJydT2GOc15RnNy5mHmzfSew==",
"engines": {
"node": ">=4.0.0"
}
},
"node_modules/mquery": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/mquery/-/mquery-5.0.0.tgz",
"integrity": "sha512-iQMncpmEK8R8ncT8HJGsGc9Dsp8xcgYMVSbs5jgnm1lFHTZqMJTUWTDx1LBO8+mK3tPNZWFLBghQEIOULSTHZg==",
"dependencies": {
"debug": "4.x"
},
"engines": {
"node": ">=14.0.0"
}
},
"node_modules/mquery/node_modules/debug": {
"version": "4.3.4",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
"dependencies": {
"ms": "2.1.2"
},
"engines": {
"node": ">=6.0"
},
"peerDependenciesMeta": {
"supports-color": {
"optional": true
}
}
},
"node_modules/mquery/node_modules/ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
},
"node_modules/ms": { "node_modules/ms": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
...@@ -940,6 +1103,14 @@ ...@@ -940,6 +1103,14 @@
"resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz", "resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz",
"integrity": "sha512-77DZwxQmxKnu3aR542U+X8FypNzbfJ+C5XQDk3uWjWxn6151aIMGthWYRXTqT1E5oJvg+ljaa2OJi+VfvCOQ8w==" "integrity": "sha512-77DZwxQmxKnu3aR542U+X8FypNzbfJ+C5XQDk3uWjWxn6151aIMGthWYRXTqT1E5oJvg+ljaa2OJi+VfvCOQ8w=="
}, },
"node_modules/punycode": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz",
"integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==",
"engines": {
"node": ">=6"
}
},
"node_modules/qs": { "node_modules/qs": {
"version": "6.11.0", "version": "6.11.0",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz", "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz",
...@@ -1099,6 +1270,11 @@ ...@@ -1099,6 +1270,11 @@
"url": "https://github.com/sponsors/ljharb" "url": "https://github.com/sponsors/ljharb"
} }
}, },
"node_modules/sift": {
"version": "16.0.1",
"resolved": "https://registry.npmjs.org/sift/-/sift-16.0.1.tgz",
"integrity": "sha512-Wv6BjQ5zbhW7VFefWusVP33T/EM0vYikCaQ2qR8yULbsilAT8/wQaXvuQ3ptGLpoKx+lihJE3y2UTgKDyyNHZQ=="
},
"node_modules/simple-update-notifier": { "node_modules/simple-update-notifier": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-2.0.0.tgz", "resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-2.0.0.tgz",
...@@ -1110,6 +1286,14 @@ ...@@ -1110,6 +1286,14 @@
"node": ">=10" "node": ">=10"
} }
}, },
"node_modules/sparse-bitfield": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz",
"integrity": "sha512-kvzhi7vqKTfkh0PZU+2D2PIllw2ymqJKujUcyPMd9Y75Nv4nPbGJZXNhxsgdQab2BmlDct1YnfQCguEvHr7VsQ==",
"dependencies": {
"memory-pager": "^1.0.2"
}
},
"node_modules/statuses": { "node_modules/statuses": {
"version": "2.0.1", "version": "2.0.1",
"resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz",
...@@ -1159,6 +1343,17 @@ ...@@ -1159,6 +1343,17 @@
"nodetouch": "bin/nodetouch.js" "nodetouch": "bin/nodetouch.js"
} }
}, },
"node_modules/tr46": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/tr46/-/tr46-3.0.0.tgz",
"integrity": "sha512-l7FvfAHlcmulp8kr+flpQZmVwtu7nfRV7NZujtN0OqES8EL4O4e0qqzL0DC5gAvx/ZC/9lk6rhcUwYvkBnBnYA==",
"dependencies": {
"punycode": "^2.1.1"
},
"engines": {
"node": ">=12"
}
},
"node_modules/type-is": { "node_modules/type-is": {
"version": "1.6.18", "version": "1.6.18",
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz",
...@@ -1179,8 +1374,7 @@ ...@@ -1179,8 +1374,7 @@
"node_modules/undici-types": { "node_modules/undici-types": {
"version": "5.26.5", "version": "5.26.5",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz",
"integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA=="
"dev": true
}, },
"node_modules/unpipe": { "node_modules/unpipe": {
"version": "1.0.0", "version": "1.0.0",
...@@ -1206,6 +1400,26 @@ ...@@ -1206,6 +1400,26 @@
"node": ">= 0.8" "node": ">= 0.8"
} }
}, },
"node_modules/webidl-conversions": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz",
"integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==",
"engines": {
"node": ">=12"
}
},
"node_modules/whatwg-url": {
"version": "11.0.0",
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-11.0.0.tgz",
"integrity": "sha512-RKT8HExMpoYx4igMiVMY83lN6UeITKJlBQ+vR/8ZJ8OCdSiN3RwCq+9gH0+Xzj0+5IrM6i4j/6LuvzbZIQgEcQ==",
"dependencies": {
"tr46": "^3.0.0",
"webidl-conversions": "^7.0.0"
},
"engines": {
"node": ">=12"
}
},
"node_modules/yallist": { "node_modules/yallist": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
"cors": "^2.8.5", "cors": "^2.8.5",
"dotenv": "^16.3.1", "dotenv": "^16.3.1",
"express": "^4.18.2", "express": "^4.18.2",
"mongoose": "^8.0.1",
"nodemon": "^3.0.1" "nodemon": "^3.0.1"
}, },
"devDependencies": { "devDependencies": {
......
import dotenv from "dotenv";
import mongoose from "mongoose";
dotenv.config();
const GoogleProviderSchema = new mongoose.Schema({
id: {
type: String,
required: true,
unique: true,
},
profileUrl: {
type: String,
},
});
const UserSchema = new mongoose.Schema({
user_id: {
type: String,
required: true,
unique: true,
},
nickname: {
type: String,
},
email: {
type: String,
unique: true,
},
google: {
type: GoogleProviderSchema,
}
});
const UserModel = mongoose.model("User", UserSchema);
const CommentSchema = new mongoose.Schema({
commentId: {
type: String,
required: true,
unique: true,
},
content: {
type: String,
required: true,
},
author: {
type: UserSchema,
required: true,
},
createdAt: {
type: Date,
default: Date.now,
},
});
const ArticleSchema = new mongoose.Schema({
title: {
type: String,
required: true,
},
articleId: {
type: String,
unique: true,
},
content: {
type: String,
required: true,
},
imageUrls: {
type: [String],
},
author: {
type: UserSchema,
required: true,
},
comments: {
type: [CommentSchema],
},
likes: {
type: [UserSchema],
},
createdAt: {
type: Date,
default: Date.now,
},
});
const ArticleModel = mongoose.model("Article", ArticleSchema);
const connectDB = async () => {
const url = process.env.MONGODB_URI;
let db;
try {
db = await mongoose.connect(url, { useNewUrlParser: true, useUnifiedTopology: true });
} catch (error) {
console.error(error);
}
return db;
}
export default { connectDB, UserModel, ArticleModel }
\ No newline at end of file
...@@ -3,9 +3,12 @@ import cors from 'cors' ...@@ -3,9 +3,12 @@ import cors from 'cors'
import path from 'path' import path from 'path'
import process from 'process' import process from 'process'
import db from './db.js'
const app = express(); const app = express();
const PORT = 8080; const PORT = 8080;
db.connectDB();
app.use(express.static(path.join(process.cwd(), '../frontend/build'))); app.use(express.static(path.join(process.cwd(), '../frontend/build')));
...@@ -32,7 +35,7 @@ function encode_utf8(s) { ...@@ -32,7 +35,7 @@ function encode_utf8(s) {
app.post('/login', (req, res) => { app.post('/login', (req, res) => {
const text = req.body; const text = req.body;
console.log(req.body.name); console.log(req.body);
res.send(req.body.name); res.send(req.body.name);
//res.redirect(200, "/main"); //res.redirect(200, "/main");
}); });
......
# compiled output
/dist
/node_modules
# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# OS
.DS_Store
# Tests
/coverage
/.nyc_output
# production
/build
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.env
*.local.env
\ No newline at end of file
This diff is collapsed.
...@@ -14,9 +14,11 @@ ...@@ -14,9 +14,11 @@
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"react-router-dom": "^6.18.0", "react-router-dom": "^6.18.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4" "web-vitals": "^2.1.4"
}, },
"devDependencies": {
"react-scripts": "5.0.1"
},
"scripts": { "scripts": {
"start": "react-scripts start", "start": "react-scripts start",
"build": "react-scripts build", "build": "react-scripts build",
......
import {GoogleLogin} from "@react-oauth/google"; import { GoogleLogin } from "@react-oauth/google";
import {GoogleOAuthProvider} from "@react-oauth/google"; import { GoogleOAuthProvider } from "@react-oauth/google";
import { useNavigate, Navigate } from "react-router-dom"; import { useNavigate, Navigate } from "react-router-dom";
import base64 from 'base-64'; import base64 from 'base-64';
...@@ -11,70 +11,72 @@ import axios from 'axios'; ...@@ -11,70 +11,72 @@ import axios from 'axios';
const GoogleLoginButton = () => { const GoogleLoginButton = () => {
const clientId = '716858812522-rb0pfisq317unkh4so5hvbu16p19kqp8.apps.googleusercontent.com' const clientId = '716858812522-rb0pfisq317unkh4so5hvbu16p19kqp8.apps.googleusercontent.com'
const navigate = useNavigate(); const navigate = useNavigate();
const goMain = () => { const goMain = () => {
navigate("/main"); navigate("/main");
} }
return ( return (
<> <>
<GoogleOAuthProvider clientId={clientId}> <GoogleOAuthProvider clientId={clientId}>
<GoogleLogin <GoogleLogin
onSuccess={(res) => { onSuccess={(res) => {
/* 발급받은 토큰은 . 을 기준으로 3 개로 나뉜다. /* 발급받은 토큰은 . 을 기준으로 3 개로 나뉜다.
aaaa.bbbb.cccc aaaa.bbbb.cccc
[base64]aaaa: 헤더 [base64]aaaa: 헤더
[base64]bbbb: 페이로드 (실질적인 데이터) [base64]bbbb: 페이로드 (실질적인 데이터)
[RS256]cccc: 서명 [RS256]cccc: 서명
RS256 : 암호화 알고리즘, JWT 서명할 때 사용한다고 함 RS256 : 암호화 알고리즘, JWT 서명할 때 사용한다고 함
*/ */
let datas = res.credential.split('.') console.log(res);
const obj = JSON.parse(b64DecodeUnicode(datas[1]));
console.log(obj); let datas = res.credential.split('.')
let response = commuTest(obj); const obj = JSON.parse(b64DecodeUnicode(datas[1]));
console.log(response); console.log(obj);
if (response) { let response = commuTest(obj);
goMain(); console.log(response);
} if (response) {
}} goMain();
onFailure={(err) => { }
console.log("Login Failed"); }}
console.log(err); onFailure={(err) => {
}} console.log("Login Failed");
/> console.log(err);
</GoogleOAuthProvider> }}
</> />
); </GoogleOAuthProvider>
</>
);
}; };
function b64DecodeUnicode(str) { function b64DecodeUnicode(str) {
// Going backwards: from bytestream, to percent-encoding, to original string. // Going backwards: from bytestream, to percent-encoding, to original string.
return decodeURIComponent(atob(str) return decodeURIComponent(atob(str)
.split('').map(function(c) { .split('').map(function (c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join('')); }).join(''));
} }
async function commuTest(payloadObj) { async function commuTest(payloadObj) {
const response = await axios({ const response = await axios({
url: 'http://localhost:8080/login', // 통신할 웹문서 url: 'http://localhost:8080/login', // 통신할 웹문서
method: 'post', // 통신할 방식 method: 'post', // 통신할 방식
data: payloadObj data: payloadObj
}); });
console.log(response) console.log(response)
if (response.status === 200) { if (response.status === 200) {
return response.data; return response.data;
} }
else { else {
return null; return null;
} }
} }
export default GoogleLoginButton export default GoogleLoginButton
\ No newline at end of file
...@@ -11,7 +11,7 @@ root.render( ...@@ -11,7 +11,7 @@ root.render(
<BrowserRouter> <BrowserRouter>
<Routes> <Routes>
<Route path="/" element={<App />} /> <Route path="/" element={<App />} />
<Route path="/main" element={<Main />} /> <Route path="/main" element={<Main />} />
</Routes> </Routes>
</BrowserRouter> </BrowserRouter>
</React.StrictMode> </React.StrictMode>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment