diff --git a/server/routes/auth.js b/server/routes/auth.js index bf2d6a0..3e94dd0 100644 --- a/server/routes/auth.js +++ b/server/routes/auth.js @@ -50,7 +50,8 @@ router.get('/github/callback', async (req, res) => { res.redirect(`/users/register?githubUsername=${githubUsername}`); } catch (error) { console.error('Error during gitHub authentication:', error); - res.status(500).json({ message: 'Internal Server Error' }); + // If the authorization process failed, redirect the user to the registration page with an error message + res.redirect(`/users/register?error=githubAuthFailed`); } }); diff --git a/server/routes/users.js b/server/routes/users.js index eb930b1..63e5d10 100644 --- a/server/routes/users.js +++ b/server/routes/users.js @@ -13,8 +13,8 @@ router.get('/login', (req, res) => { }); router.get('/register', (req, res) => { - const { githubUsername } = req.query; - res.render('register', { githubUsername }); + const { githubUsername, error } = req.query; + res.render('register', { githubUsername, error }); }); async function getUserRepositories(githubToken) { diff --git a/server/views/register.pug b/server/views/register.pug index 73ce03a..7572b6d 100644 --- a/server/views/register.pug +++ b/server/views/register.pug @@ -8,6 +8,9 @@ block content p.text-white-50.mb-5 Please finish the following authorizations! .d-flex.flex-column.align-items-center + if error == 'githubAuthFailed' + p.text-danger.mb-3 GitHub authorization failed! Please try again! + if githubUsername button.btn.btn-success.btn-lg.mb-3.w-100(type='button' disabled) i.fab.fa-github.fa-lg(style='margin-right: 8px')