1
0
mirror of synced 2025-10-29 02:19:19 +00:00

login system & basic design system

This commit is contained in:
Valentin PUCCETTI
2023-09-10 13:57:57 +02:00
parent 4fec96b4b1
commit 8340a135d6
25 changed files with 1362 additions and 0 deletions

38
services/auth.service.js Normal file
View File

@@ -0,0 +1,38 @@
const {default: axios} = require("axios");
async function getToken(code) {
var client_id = process.env.GITHUB_CLIENT_ID
var client_secret = process.env.GITHUB_CLIENT_SECRET
const request = await fetch("https://github.com/login/oauth/access_token", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
client_id,
client_secret,
code
})
});
const text = await request.text();
console.log("RESPONSE!!!");
const params = new URLSearchParams(text);
return params.get("access_token");
};
async function fetchUser(access_token) {
console.log('called')
const { data } = await axios({
url: 'https://api.github.com/user',
method: 'get',
headers: {
Authorization: `token ${access_token}`,
},
});
return data;
};
module.exports = {
fetchUser,
getToken
};