Showing
2 changed files
with
11 additions
and
9 deletions
... | @@ -89,13 +89,14 @@ export const finishGithubLogin = async (req,res) => | ... | @@ -89,13 +89,14 @@ export const finishGithubLogin = async (req,res) => |
89 | { | 89 | { |
90 | 90 | ||
91 | const config = { | 91 | const config = { |
92 | - client_id: process.env.O_AUTH_CLIENT_ID, | 92 | + client_id: process.env.O_Auth_client_id, |
93 | client_secret : process.env.O_Auth_scret, | 93 | client_secret : process.env.O_Auth_scret, |
94 | code: req.query.code | 94 | code: req.query.code |
95 | } | 95 | } |
96 | const params = new URLSearchParams(config).toString(); | 96 | const params = new URLSearchParams(config).toString(); |
97 | const baseURL = `https://github.com/login/oauth/access_token`; | 97 | const baseURL = `https://github.com/login/oauth/access_token`; |
98 | const finalURL = `${baseURL}?${params}`; | 98 | const finalURL = `${baseURL}?${params}`; |
99 | + console.log(finalURL) | ||
99 | const data = await fetch(finalURL,{ | 100 | const data = await fetch(finalURL,{ |
100 | method:"POST", | 101 | method:"POST", |
101 | headers:{ | 102 | headers:{ |
... | @@ -107,12 +108,13 @@ export const finishGithubLogin = async (req,res) => | ... | @@ -107,12 +108,13 @@ export const finishGithubLogin = async (req,res) => |
107 | { | 108 | { |
108 | const {access_token} = token; | 109 | const {access_token} = token; |
109 | const apiUrl = "https://api.github.com" | 110 | const apiUrl = "https://api.github.com" |
110 | - const getUserData = await fetch(`${apiUrl}/user`,{ | 111 | + const userRequest = await ( |
111 | - method:"GET", | 112 | + await fetch(`${apiUrl}/user`, { |
112 | - headers:{ | 113 | + headers: { |
113 | - Authorization: `token ${access_token}` | 114 | + Authorization: `token ${access_token}`, |
114 | - } | 115 | + }, |
115 | - }); | 116 | + }) |
117 | + ).json(); | ||
116 | const emailData = await ( | 118 | const emailData = await ( |
117 | await fetch(`${apiUrl}/user/emails`,{ | 119 | await fetch(`${apiUrl}/user/emails`,{ |
118 | method:"GET", | 120 | method:"GET", |
... | @@ -129,7 +131,7 @@ export const finishGithubLogin = async (req,res) => | ... | @@ -129,7 +131,7 @@ export const finishGithubLogin = async (req,res) => |
129 | if(!user){ | 131 | if(!user){ |
130 | user = await User.create({ | 132 | user = await User.create({ |
131 | email:emailObj.email, | 133 | email:emailObj.email, |
132 | - username:userData.login, | 134 | + username:userRequest.login, |
133 | password:"", | 135 | password:"", |
134 | isO_Auth: true, | 136 | isO_Auth: true, |
135 | }); | 137 | }); | ... | ... |
... | @@ -11,7 +11,7 @@ const userSchema = new mongoose.Schema({ | ... | @@ -11,7 +11,7 @@ const userSchema = new mongoose.Schema({ |
11 | 11 | ||
12 | userSchema.pre('save', async function(){ | 12 | userSchema.pre('save', async function(){ |
13 | console.log("Users password:", this.password); | 13 | console.log("Users password:", this.password); |
14 | - this.password = await bcrypt.hash(this.password, 5);`` | 14 | + this.password = await bcrypt.hash(this.password, 5); |
15 | console.log("Users password:", this.password); | 15 | console.log("Users password:", this.password); |
16 | }) | 16 | }) |
17 | 17 | ... | ... |
-
Please register or login to post a comment