Skip to content

Commit

Permalink
few updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Unknown39825 committed Jul 11, 2021
1 parent bdca80b commit 7ad6564
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 13 deletions.
28 changes: 27 additions & 1 deletion authenticate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var passport = require("passport");
var JwtStrategy = require("passport-jwt").Strategy;
var ExtractJwt = require("passport-jwt").ExtractJwt;
const User = require("./models/User/user");

const jwt = require("jsonwebtoken");
var opts = {
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(), // toe get token from the auth header
secretOrKey: process.env.secretKey, // secret key
Expand Down Expand Up @@ -82,3 +82,29 @@ exports.isVerifiedUser = (req, res, next) => {
)
.catch((err) => next(err));
};

exports.verifyToken = (req, res) => {
if (!opts.jwtFromRequest(req)) {
return res.status(404).json({ success: false, error: "Token Missing !!" });
} else {
jwt.verify(
opts.jwtFromRequest(req),
process.env.secretKey,
(err, decoded) => {
if (err) {
return res
.status(401)
.json({ success: false, error: err.message, status: err.name });
}
if (!decoded) {
return res
.status(500)
.json({ success: false, error: "Something went wrong" });
}
return res
.status(200)
.json({ success: true, status: "Token Valid !!", user: decoded._id });
}
);
}
};
1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "fine-arts",
"version": "0.1.0",
"private": true,
"proxy":"http://localhost:8000",
"dependencies": {
"@testing-library/jest-dom": "^5.12.0",
"@testing-library/react": "^11.2.7",
Expand Down
10 changes: 5 additions & 5 deletions client/src/Components/BackDrop/areas.json
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
"fillColor": "#ff000026",
"strokeColor": "black",
"coords": [423, 327, 25],
"href": "javascript:void(0);"
"href": ""
},
{
"title": "Ceiling",
Expand All @@ -222,7 +222,7 @@
"fillColor": "#ff000026",
"strokeColor": "black",
"coords": [492, 283, 25],
"href": "javascript:void(0);"
"href": ""
},
{
"title": "Ceiling",
Expand Down Expand Up @@ -348,7 +348,7 @@
"fillColor": "#ff000026",
"strokeColor": "black",
"coords": [303, 179, 14],
"href": "javascript:void(0);"
"href": "/"
},
{
"title": "Ceiling",
Expand Down Expand Up @@ -456,7 +456,7 @@
"fillColor": "#ff000026",
"strokeColor": "black",
"coords": [584, 155, 16],
"href": "javascript:void(0);"
"href": ""
},
{
"title": "Ceiling",
Expand Down Expand Up @@ -484,6 +484,6 @@
"fillColor": "#ff000026",
"strokeColor": "black",
"coords": [685, 187, 12],
"href": "javascript:void(0);"
"href": ""
}
]
24 changes: 24 additions & 0 deletions client/src/Components/Base/Base.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Aos from 'aos';
import axios from 'axios';
import React, { useEffect, useState } from 'react'
import { isAuthenticated } from '../Authentication/auth';
import Footer from '../Footer/Footer'

import Navbar from '../NavBar/Navbar'
Expand All @@ -18,6 +19,7 @@ export default function Base({

try {
const res = await axios.get('/api/contributor');

if (res.data) {
setConributor(res.data);

Expand All @@ -29,10 +31,32 @@ export default function Base({
}

}

const validateUser = async()=>{

const { token } = isAuthenticated();

if(!token)
return;

try {
const config = {
headers: { Authorization: `Bearer ${token}` }
};
const res = await axios.get('/user/auth', config);

} catch (error) {

localStorage.removeItem("jwt");
window.alert("Session Expire Login Again");

}
}

useEffect(() => {

FetchData();
validateUser();

Aos.init();

Expand Down
2 changes: 1 addition & 1 deletion client/src/Components/Footer/Footer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function Footer({ contributors}) {
<h2>Top Contributors</h2>
<div className="flex-row">

{contributors.map((cont) => <h2 className="contributor">
{contributors.map((cont) => <h2 key={cont._id} className="contributor">
<span>{cont.user.firstname}</span>(
<span>{cont.count}</span>)

Expand Down
2 changes: 1 addition & 1 deletion client/src/Components/Homepage/PostContent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function PostContent({data}) {
<p>{data.desc}

</p>
<button className="btn post-btn" onClick="window.location='photogallery.html#gal';">show related&nbsp; <i className="fas fa-arrow-right"></i></button>
<button className="btn post-btn" >show related&nbsp; <i className="fas fa-arrow-right"></i></button>
</div>
</div>
<hr/>
Expand Down
4 changes: 2 additions & 2 deletions client/src/Components/NavBar/Navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const Navbar = () => {
<div className="nav-menu flex-row">
<div className="nav-brand">

<Link to="/" className="text-grey bold">
<Link to="/" className="text-grey bold">
<img className="logo" src={logo} width="50px" alt="" />FineArts <span className="red">
NIT Kurukhetra</span>
</Link>
Expand Down Expand Up @@ -57,7 +57,7 @@ const Navbar = () => {
!isAuthenticated() && <NavLink to="/signup" activeClassName="active" className=" left" >signup</NavLink>
}
{
isAuthenticated() && <Link onClick={logout} className=" left" >Signout</Link>
isAuthenticated() && <Link onClick={logout} to="/" className=" left" >Signout</Link>
}
</div>

Expand Down
5 changes: 2 additions & 3 deletions routes/Users/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const express= require("express");
require("dotenv").config();
const { registerUser, getUser, loginUser,logoutUser, logoutUserAll, verifyEmail, forgotPassword, verifyOtp} = require("../../controllers/User/user");
const router = express.Router();
const {verifyAdmin, verifyUser,isVerifiedUser} = require('../../authenticate');
const {verifyAdmin, verifyUser,isVerifiedUser, verifyToken} = require('../../authenticate');
const passport = require('passport');
const User = require("../../models/User/user");

Expand All @@ -21,8 +21,7 @@ router.post("/login",(req,res,next) => {

router.get("/logout",verifyUser,logoutUser);
router.get("/logoutall",verifyUser,logoutUserAll);

router.put("/forgot",forgotPassword);
router.put("/otp/verify",verifyOtp);

router.get("/auth", verifyToken);
module.exports =router;

0 comments on commit 7ad6564

Please sign in to comment.