Skip to content

Commit

Permalink
Merge pull request #42 from rogershi-dev/feature/registration-auth
Browse files Browse the repository at this point in the history
Added an error message when GitHub authorization failed.
  • Loading branch information
rogershi-dev authored Jul 10, 2024
2 parents 9591a78 + 9b2c8b7 commit 617a842
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion server/routes/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
}
});

Expand Down
4 changes: 2 additions & 2 deletions server/routes/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions server/views/register.pug
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 617a842

Please sign in to comment.