Skip to content

Commit

Permalink
+ Refactor :
Browse files Browse the repository at this point in the history
1. Migrated from node-localstorage > store
  • Loading branch information
glantrox committed Jul 5, 2024
1 parent 2121838 commit 8d0b228
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
12 changes: 11 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"imgur-uploader": "^4.2.1",
"multer": "^1.4.5-lts.1",
"node": "^22.3.0",
"node-localstorage": "^3.0.5"
"node-localstorage": "^3.0.5",
"store": "^2.0.12"
},
"devDependencies": {
"@babel/core": "^7.24.7",
Expand Down
5 changes: 2 additions & 3 deletions src/data/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ const supabase = createClient(supabaseURL, supabaseKey);
const imgurUpload = require('../utils/imgur');

// Local Storage
const { LocalStorage } = require('node-localstorage');
const localStorage = new LocalStorage('./scratch');
const localStorage = require(`store`)

// Body-Parser
const bodyParser = require(`body-parser`);
Expand All @@ -37,7 +36,7 @@ service.get(`/auth-user`, async (req, res) => {
if(clientPassword !== password) {
return res.status(401).send(`Wrong Password`);
}
localStorage.setItem('isLoggedIn', true);
localStorage.set(`auth`, true);
res.status(200).send(`Login Succeed`);
} catch (error) {
res.status(500).send(`Client Exception - ${error}`);
Expand Down
5 changes: 2 additions & 3 deletions src/routes/middleware.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const { LocalStorage } = require('node-localstorage');
const localStorage = new LocalStorage('./scratch');
const localStorage = require(`store`);

module.exports = {
authMiddleware: async (req,res, next) => {
const isLoggedIn = localStorage.getItem(`isLoggedIn`)
const isLoggedIn = localStorage.get(`auth`)
// Re-Authenticate to Login Screen
if(!isLoggedIn) {
return res.redirect(`/login`);
Expand Down

0 comments on commit 8d0b228

Please sign in to comment.