Skip to content

Commit f18f8e2

Browse files
chore: refactor to allow callback url to hit backend
Signed-off-by: Desmond Obisi <[email protected]>
1 parent 623f9e9 commit f18f8e2

File tree

3 files changed

+17
-36
lines changed

3 files changed

+17
-36
lines changed

providers/github/auth.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -194,21 +194,8 @@ const handleOAuthCallback = async (req, res) => {
194194
}
195195
};
196196

197-
/**
198-
* Sets up the provided Express app routes for GitLab
199-
* @param {*} app Express application instance
200-
*/
201-
const githubAuthCallback = (app) => {
202-
if (process.env.NODE_ENV === "production") {
203-
app.post("/api/callback/github", handleOAuthCallback);
204-
} else if (process.env.NODE_ENV === "development") {
205-
app.get("/api/callback/github", handleOAuthCallback);
206-
}
207-
};
208-
209197
module.exports = {
210198
githubAuth,
211-
githubAuthCallback,
212199
handleOAuthCallback,
213200
githubApp,
214201
};

providers/gitlab/auth.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const requestAccessToken = async (code) => {
6565
* @returns A json object with `user_info` and `errors`
6666
* */
6767

68-
const handleOAuthCallback = async (req, res) => {
68+
const handleOAuthCallbackGitlab = async (req, res) => {
6969
const code = req.body.code ?? req.query.code;
7070

7171
const { access_token: accessToken, errors: accessTokenErrors } =
@@ -152,19 +152,7 @@ const handleOAuthCallback = async (req, res) => {
152152
}
153153
};
154154

155-
/**
156-
* Sets up the provided Express app routes for GitLab
157-
* @param {*} app Express application instance
158-
*/
159-
const gitlabAuthCallback = (app) => {
160-
if (process.env.NODE_ENV === "production") {
161-
app.post("/api/callback/gitlab", handleOAuthCallback);
162-
} else if (process.env.NODE_ENV === "development") {
163-
app.get("/api/callback/gitlab", handleOAuthCallback);
164-
}
165-
};
166-
167155
module.exports = {
168156
gitlabAuth,
169-
gitlabAuthCallback,
157+
handleOAuthCallbackGitlab,
170158
};

routes/index.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,9 @@ const eventBadging = require("../event_badging/index.js");
44
const github_helpers = require("../providers/github/APICalls.js");
55
const gitlab_helpers = require("../providers/gitlab/APICalls.js");
66
const { getAllEvents } = require("../database/controllers/event.controller.js");
7-
const {
8-
githubAuth,
9-
githubAuthCallback,
10-
githubApp,
11-
gitlabAuth,
12-
gitlabAuthCallback,
13-
} = require("../providers/index.js");
7+
const { githubAuth, githubApp, gitlabAuth } = require("../providers/index.js");
8+
const { handleOAuthCallback } = require("../providers/github/auth.js");
9+
const { handleOAuthCallbackGitlab } = require("../providers/gitlab/auth.js");
1410

1511
/**
1612
* Redirects the user to the GitHub OAuth login page for authentication.
@@ -160,8 +156,18 @@ const setupRoutes = (app) => {
160156
app.get("/api/login", login);
161157

162158
//callbacks
163-
githubAuthCallback(app);
164-
gitlabAuthCallback(app);
159+
if (process.env.NODE_ENV === "production") {
160+
app.post("/api/callback/github", handleOAuthCallback);
161+
} else if (process.env.NODE_ENV === "development") {
162+
app.get("/api/callback/github", handleOAuthCallback);
163+
}
164+
165+
if (process.env.NODE_ENV === "production") {
166+
app.post("/api/callback/gitlab", handleOAuthCallbackGitlab);
167+
} else if (process.env.NODE_ENV === "development") {
168+
app.get("/api/callback/gitlab", handleOAuthCallbackGitlab);
169+
}
170+
165171
app.get("/api/badgedRepos", badgedRepos);
166172
app.post("/api/repos-to-badge", reposToBadge);
167173

0 commit comments

Comments
 (0)