Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the access token now if the user enter incorrect token it will re… #88

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vs/ProjectSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"CurrentProjectSetting": null
}
8 changes: 8 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"ExpandedNodes": [
"",
"\\js"
],
"SelectedNode": "\\js\\usernameSelection.js",
"PreviewInSolutionExplorer": false
}
Binary file added .vs/curiosity/v16/.suo
Binary file not shown.
Binary file added .vs/slnx.sqlite
Binary file not shown.
52 changes: 18 additions & 34 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,46 +84,30 @@ if (window.localStorage) {
}
USERNAMES = JSON.parse(localStorage.getItem('usernames'));

if (!localStorage.getItem('accessToken')) {
swal({
title: 'Submit Github Token',
const jwt = require('jsonwebtoken');


module.exports = function(req,res,next){
title: 'Submit Github Token',
html: "Curiosity requires a Github Token to access Github API. Your token will be saved in LocalStorage. So don't worry. Get new token <a target='_blank' href='https://github.com/settings/tokens/new?description=Curiosity'>here</a>.",
input: 'text',
showCancelButton: true,
confirmButtonText: 'Submit',
showLoaderOnConfirm: false,
preConfirm(token) {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (token === '') {
reject(new Error('Enter Valid Token'));
} else {
const url = `https://api.github.com/?access_token=${token}`;
axios({
url,
method: 'get',
responseType: 'json',
}).then(() => {
localStorage.setItem('accessToken', token);
resolve();
}).catch(() => reject(new Error('Error: invalid token')));
}
}, 1000);
});
},
allowOutsideClick: false,
}).then((token) => {
accessToken = token;
getData();
renderLanguageSelector();
renderUsernames();
swal({
type: 'success',
title: 'Thank You',
});
});
const token = req.header('auth-token');
if(!token)
return res.status(401).send('Access Denied');

try{
const verified = jwt.verify(token, process.env.TOKEN_SECRET);
req.user = verified;
next();
} catch(err){
res.status(400).send('Invalid Token');

}
} else {
}
else {
alert('Sorry! LocalStorage is not available');
}

Expand Down